C-c to c ++ annotation Conversion

Source: Internet
Author: User

C-c to c ++ annotation Conversion

# Include <stdio. h> typedef enum Tag {C_ANNOTAION_START = 0, // start of C annotation C_ANNOTAION_END = 1, // end of C annotation} Tag; typedef enum State {SUCCESS = 1, // successful OPEN_FILE_ERROR, // NO_MATCH when opening the FILE, // the FILE does not match OTHER, // OTHER} State; State AnnotationConvert (FILE * cIn, FILE * cOut) {char FirstCh, secondCh; Tag Is_Start = C_ANNOTAION_END; // whether to start to convert do {FirstCh = fgetc (cIn); switch (FirstCh) {// 1. in general, // * int I = 0; */case '/': Se CondCh = fgetc (cIn); // 3. matching Problem // * int I = 0;/* xxxxx */if (SecondCh = '*' & Is_Start = C_ANNOTAION_END) {fputc ('/', cOut); fputc ('/', cOut); Is_Start = C_ANNOTAION_START;} else if (SecondCh = '/') // c ++ comments {char Next = fgetc (cIn); fputc ('/', cOut); fputc ('/', cOut); while (Next! = '\ N' & Next! = EOF) {fputc (Next, cOut); Next = fgetc (cIn);} // FirstCh = Next; fseek (cIn,-1, SEEK_CUR );} else {fputc (FirstCh, cOut); fputc (SecondCh, cOut);} break; case '*': SecondCh = fgetc (cIn); // 2. line feed problem/5. continuous annotation problem // * int I = 0; */int j = 0; // * int I = 0; */if (SecondCh = '/') {char Next = 0; Next = fgetc (cIn); if (Next! = '\ N' & Next! = EOF) {fseek (cIn,-1, SEEK_CUR); fputc ('\ n', cOut);} else {fputc (' \ n', cOut );} is_Start = C_ANNOTAION_END;} else if (SecondCh = '*') {fputc (FirstCh, cOut); fseek (cIn,-1, SEEK_CUR); break ;} else {fputc (FirstCh, cOut); fputc (SecondCh, cOut);} break; // 4. multi-line comment case '\ N': fputc (' \ n', cOut); if (Is_Start = C_ANNOTAION_START) {fputc ('/', cOut ); fputc ('/', cOut);} break; default: fputc (Fir StCh, cOut); break;} while (FirstCh! = EOF); if (Is_Start = C_ANNOTAION_START) {return NO_MATCH;} return SUCCESS;} State StartAnnotationConvert (const char * input, const char * output) {FILE * cIn = fopen (input, "r"); FILE * cOut = fopen (output, "w"); State ret = 0; if (cIn = NULL) {fclose (cOut); return OPEN_FILE_ERROR;} if (cOut = NULL) {fclose (cIn); return OPEN_FILE_ERROR;} ret = AnnotationConvert (cIn, cOut ); fclose (cIn); fclos E (cOut); return ret;} int main () {State ret = StartAnnotationConvert ("input. c "," output. c "); if (ret = SUCCESS) {printf (" conversion successful! \ N ");} else if (ret = NO_MATCH) {printf (" the matching end \ n "is not found in the document);} else if (ret = OPEN_FILE_ERROR) {printf ("failed to open the file \ n") ;}return 0 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.