can be divided into 7 different situations
1. General Information
/* int i = 0; */
2. Line break issues
/* int i = 0; */Int j = 0;
3. Matching issues
/int i = 0;/*xxxxx/
4. Multi-line annotation issues
/*
int i=0;
int j = 0;
int k = 0;
*/int k = 0;
5. Continuous annotation Issues
////
6. Continuous **/problem
/*/
7.c++ Comment Questions
/xxxxxxxxxxxx/
result after conversion
1. General Information
int i = 0;
2. Line break issues
int i = 0;
int j = 0;
3. Matching issues
int i = 0;/*xxxxx
4. Multi-line annotation issues
//
int i=0;
int j = 0;
int k = 0;
//
int k = 0;
5. Continuous annotation Issues
//
//
6. Continuous **/problem
//*
7.c++ Comment Questions
/xxxxxxxxxxxx/
#include <stdio.h>#include <assert.h>#include <errno.h>#pragma warning (disable:4996)typedef enumstate{succeed,//Conversion SuccessFile_error,//File ErrorNot_match,//Comment mismatchOTHERS,//Other errors}state;typedef enumtag{Tag_bedin,//within the C comment sectionTag_end,//End of comment}tag; State Annotationconvert (file* InFile, file* OutFile) {tag tag = tag_end;CharFirstch;CharSECONDCH; ASSERT (InFile); ASSERT (OutFile); Do{Firstch = fgetc (InFile);Switch(Firstch) { Case('/'): Secondch = fgetc (InFile);if(SECONDCH = =' * '&& tag = = tag_end) {FPUTC ('/', OutFile); FPUTC ('/', OutFile); tag = Tag_bedin; }Else{FPUTC (Firstch, OutFile); FPUTC (SECONDCH, OutFile);if(SECONDCH = ='/') {CharNextch; Do{Nextch = fgetc (InFile); FPUTC (Nextch, OutFile); } while(Nextch! =' \ n '&& Nextch! = EOF); } } Break; Case(' \ n '): Fputc (Firstch, OutFile);if(tag = = Tag_bedin) {FPUTC ('/', OutFile); FPUTC ('/', OutFile); } Break; Case(' * '): Secondch = fgetc (InFile);if(SECONDCH = ='/') {CharNextch = fgetc (InFile); tag = Tag_end; FPUTC (' \ n ', OutFile);if(Nextch = ='/') {fseek (InFile,-1, seek_cur); }Else if(Nextch! =' \ n ') {FPUTC (Nextch, OutFile); } }Else{FPUTC (Firstch, OutFile); Fseek (InFile,-1, seek_cur); } Break;default: Fputc (Firstch, OutFile); Break; } } while(Firstch! = EOF);if(tag = = Tag_end) {returnsucceed; }Else returnNot_match;}intStartconvert () {state S;Const Char* Infilename ="Input.c";Const Char* Outfilename ="Output.c"; file* InFile = fopen (Infilename,"R"); file* OutFile = fopen (Outfilename,"W");if(InFile = = NULL) {Perror ("Input.c");returnFile_error; }if(OutFile = = NULL) {fclose (InFile); Perror ("Output.c");returnFile_error; } s = Annotationconvert (InFile, OutFile); Fclose (InFile); Fclose (OutFile);returns;}intMain () {state ret = Startconvert ();if(ret = = succeed) {printf("Conversion succeeded \ n"); }Else if(ret = = Not_match) {printf("comment does not match \ n"); }Else if(ret = = File_error) {printf("File Error:%d\n", errno); }Else{printf("other error \ n"); } getchar ();return 0;}
Convert C language Comments to C + + comments