Skip to main content
Clarified.
Source Link

deleting Deleting (some) comments from a C program

I need to use a bash script to delete only certain commentsfull-line old-style comments from a C program, not all of them i. Thise., comments that begin (/*) and end (*/) on the same line, with no code on the same line.  This is an example of what the C program looks like:

/* Comment 1 */
printf("It is /* Comment 2 */\n");
x = 5; /* Comment 3 */
            /* Comment 4 */
/* Comment 5 */ y = 0;
            /*
             * Comment 6
             */
            // Comment 7

But I need it to look like this:

printf("It is /* Comment 2 */\n");
 x = 5; /* Comment 3 */
 /* Comment 5 */ y = 0;
            /*
             * Comment 6
             */
            // Comment 7

I do know how to delete all comments but just not sure on how to just remove certain ones.

The script should read inputs from a text file, and write outputs into another file, and all the I/O file names must be given in the command-line.

deleting (some) comments from a C program

I need to use a bash script to delete only certain comments from a C program, not all of them. This is what the C program looks like:

/* Comment 1 */
printf("It is /* Comment 2 */\n");
x = 5; /* Comment 3 */
            /* Comment 4 */
/* Comment 5 */ y = 0;

But I need it to look like this:

printf("It is /* Comment 2 */\n");
 x = 5; /* Comment 3 */
 /* Comment 5 */ y = 0;

I do know how to delete all comments but just not sure on how to just remove certain ones.

The script should read inputs from a text file, and write outputs into another file, and all the I/O file names must be given in the command-line.

Deleting (some) comments from a C program

I need to use a bash script to delete full-line old-style comments from a C program, i.e., comments that begin (/*) and end (*/) on the same line, with no code on the same line.  This is an example of what the C program looks like:

/* Comment 1 */
printf("It is /* Comment 2 */\n");
x = 5; /* Comment 3 */
            /* Comment 4 */
/* Comment 5 */ y = 0;
            /*
             * Comment 6
             */
            // Comment 7

But I need it to look like this:

printf("It is /* Comment 2 */\n");
 x = 5; /* Comment 3 */
 /* Comment 5 */ y = 0;
            /*
             * Comment 6
             */
            // Comment 7

I do know how to delete all comments but just not sure on how to just remove certain ones.

The script should read inputs from a text file, and write outputs into another file, and all the I/O file names must be given in the command-line.

More specific title
Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

deleting (some) comments from a C program

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
deleted 3 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237
Loading
added 151 characters in body
Source Link
Loading
Source Link
Loading