Remove the annotations in C code,
1. Single note//;
2. Multi-line annotation/**/;
3. A single-line comment ends with "\" and the next line is also commented;
4. The annotations in the string are not processed.
Said to be C language, but in fact all of the C family can, such as Java.
Gadgets: removing C language annotations
Copy Code code as follows:
#include <stdio.h>
int main (int argc, char* argv[]) {
enum {
Literal
Single
multiple,
String
mode = literal;
Char last = 0, current;
while (current = GetChar ())!= EOF) {
Switch (mode) {
Case Single: {
if (last!= ' \ \ r ' && (current = = ' \ n ' | | | |
Putchar (current);
current = 0;
mode = literal;
}
} break;
Case multiple: {
if (last = = ' * ' && current = = ') {
current = 0;
mode = literal;
}
} break;
Case string: {
if (last = = ' \ ') {
Putchar (last);
Putchar (current);
else if (current!= ' \ \) {
Putchar (current);
if (current = = "") {
mode = literal;
}
}
} break;
Default: {
if (last = = '/') {
if (current = = '/') {
mode = single;
else if (current = = ' * ') {
mode = multiple;
} else {
Putchar (last);
Putchar (current);
}
else if (current!= '/') {
Putchar (current);
if (current = = "") {
mode = string;
}
}
} break;
}
last = current;
}
return 0;
}
Test code
Copy Code code as follows:
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
Not show\
Not show\
Not show
Not show
* Not show/*
int is; Not show
int/* not show */MS; * Not show/*
Double DS; Not show\
Not show\
Not show
Double DM; /* ...
Not show
Not show */float FS; /**
* Now Show
*/
float/**/FM;
Char cs[] = "AAA///***/";
Char cm1[] =/* Not show */"hello*/";
Char cm2[] = "/*redraiment" */Not show * * *;
/* printf ("/////"); */
return exit_success;
}
The code after processing
Copy Code code as follows:
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
int is;
int MS;
Double DS;
Double DM; Float FS;
float FM;
Char cs[] = "AAA///***/";
Char cm1[] = "hello*/";
Char cm2[] = "/*redraiment";
return exit_success;
}