I have a directory of C files. I want to remove all types of comments from these source files.
For example, let's say I have a source code that is similar to the following file.
#include <stdio.h>
int main() {
int number;
/* Sample Multiline Comment
* Line 1
* Line 2
*/
printf("Enter an integer: ");
// reads and stores input
scanf("%d", &number);
printf("You entered: %d", number); //display output
return 0;
/* Comment */
}
I want to remove all types of comments in this code. This includes,
//
/* */
/*
*
*/
I have attempted to carry out this task by using a sed command.
find . -type f |xargs sed -i 's,/\*\*,,g;s,\*/,,g;s,/\*,,g;s,//,,g'
This only removes the above comment symbols itself but not the comment. I would like to remove the entire comment along with the above three comment symbols.
How can I achieve this criteria.