How To Write a program to remove all comments from a C program.

Write a program to remove all comments from a C program.


  1. #include <stdio.h> // Includes the standard INPUT/OUTPUT library.
  2. #include "lib/helpers.h" /* Includes our own helper functions. */
  3.  
  4. int main(void)
  5. {
  6.     printf(/* cmt1 */"%d" /* cmt2 */ "\n", 10);  /*
  7. */
  8.  
  9.     char* str = "foo \
  10.                  jedi" /* cmtX */ " \
  11.                  bar";
  12.  
  13.     printf("what /* about this */ pal?\n");
  14.  
  15.     char arr[3] = {'a' /* cmt3 */, 'b', /* cmt4 */ 'c'}; // remove me
  16.     // Remove ME TOO PLEASE!!!
  17.  
  18.     return 0;
  19. }
  20.  
  21. /* A multi
  22.  * line
  23.  * comment
  24. */
  25.  
  26. // mark ini, mark end positions
  27. // IN  \n OUT
  28.  
  29. /* IN */ //OUT, but not if IN string.


Learn More :