[C Language] C language annotation is converted into C ++ annotation ., Note
1. General situation
/* Int I = 0 ;*/
2. line feed Problems
/* Int I = 0; */int j = 0;
/* Int I = 0 ;*/
Int j = 0;
3. Matching Problems
/Int I = 0;/* xxxxx/
4. Multi-line comment
/*
Int I = 0;
Int j = 0;
Int k = 0;
*/Int k = 0;
5. Continuous comments
////
6. Continuous/Problem **
//*
7. C ++ comments
///Xxxxxxxxxxxx/
# Define _ CRT_SECURE_NO_WARNINGS # include <stdio. h> # include <stdlib. h> # include <assert. h> typedef enum TAG {TAGBEGIN, TAGEND,} TAG; typedef enum STATE {SUCCESS, NO_MATCH,} STATE; STATE Annotation_Convert (FILE * infile, FILE * outfile) {TAG tag = TAGEND; assert (infile); assert (outfile); char firstCh, secondCh; do {firstCh = fgetc (infile); switch (firstCh) {case '/': secondCh = fgetc (infile); if (secondCh = = '*' & Tag = TAGEND) // process general conditions and matching conditions {fputc ('/', outfile); fputc ('/', outfile ); tag = TAGBEGIN;} else {fputc (firstCh, outfile); fputc (secondCh, outfile); if (secondCh = '/') // Process C ++ comments: /// * abcdefgh */{char next; do {next = fgetc (infile); fputc (next, outfile);} while (next! = '\ N' & next! = EOF) ;}} break; case '*': secondCh = fgetc (infile); if (secondCh = '/') {char next = fgetc (infile ); if (next! = '\ N' & next! = EOF) // handle line breaks/* int I = 0; */in t j = 0; {// and continuous comments/** // **/fputc ('\ n', outfile); fseek (infile,-1, SEEK_CUR );} tag = TAGEND;} else // processing continuity **/condition:/*********/{fputc (firstCh, outfile); fseek (infile,-1, SEEK_CUR);} break; case '\ N': fputc (' \ n', outfile); if (tag = TAGBEGIN) // process multi-line comments/* int I = 0; {// int j = 0; fputc ('/', outfile); // */int m = 0; fputc ('/', outfile);} break; default: fputc (firs) TCh, outfile); break;} while (firstCh! = EOF); if (tag = TAGEND) {return SUCCESS;} else {return NO_MATCH ;}} int main () {STATE s; FILE * infile = fopen ("input3.c", "r"); FILE * outfile = fopen ("output3.c", "w"); if (infile = NULL) {perror ("error"); exit (EXIT_FAILURE) ;}if (outfile = NULL) {fclose (infile); perror ("error"); exit (EXIT_FAILURE );} s = Annotation_Convert (infile, outfile); if (s = SUCCESS) {printf ("matching successful! \ N ") ;}if (s = NO_MATCH) {printf (" mismatch! \ N ") ;}fclose (infile); fclose (outfile); return 0 ;}
Input. coutput. c