Annotation conversion (c to c ++)

Source: Internet
Author: User

Annotation conversion (c to c ++)

// The process in input. c is as follows:

Input. c



/* Int I = 0 ;*/
/* Int y = 0; */int j = 0;
/* Int x = 0;/* 12345678 */
/*
Int h = 0;
Int g = 0;
Int j = 0;
*/Int q = 0;
/**//**/
/********/

/// * 1234567890 */

Source File Annotationconvert. c

 

 

# Include
 
  
# Include
  
   
# Include # pragma warning (disable: 4996) typedef enum STATE {FILE_ERROR, // file error FILE_SUCCESS, // file success other_error, // other errors NO_MATCH, // FILE mismatch} STA; typedef enum tag {tag_begin, // tag_end in the comment, // not in the comment} TAG; STA AnnotationConvert (FILE * infile, FILE * outfile) {char firstch, secondch; int next; assert (infile); assert (outfile); TAG a = tag_end; do {firstch = fgetc (infile); switch (firstch) {case '/': secondch = fgetc (infile); if (sec Ondch = '*' & a = tag_end) {fputc ('/', outfile); fputc ('/', outfile); a = tag_begin ;} else if (secondch = '/') {fputc (firstch, outfile); fputc (secondch, outfile); next = fgetc (infile); while (next! = EOF & next! = '') {Fputc (next, outfile); next = fgetc (infile);} a = tag_end;} else {fputc (firstch, outfile); fputc (secondch, outfile);} break; case '*': secondch = fgetc (infile); if (secondch = '/') {fputc ('', outfile ); a = tag_end;} else if (secondch = '*') {fputc (firstch, outfile); fseek (infile,-1, SEEK_CUR);} else {fputc (firstch, outfile); fputc (secondch, outfile);} break; case '': if (a = tag_begin) {fputc (firstch, outfile ); Fputc ('/', outfile); fputc ('/', outfile);} else {fputc (firstch, outfile);} break; default: fputc (firstch, outfile ); break;} while (firstch! = EOF); if (a = tag_end) {return FILE_SUCCESS;} else {return NO_MATCH;} return 0;} STA StartConvert () {STA s; const char * infileName = input. c; const char * outfileName = output. c; FILE * infile = fopen (infileName, r); FILE * outfile = fopen (outfileName, w); if (infile = NULL) {return FILE_ERROR ;} if (outfile = NULL) {fclose (infile); return FILE_ERROR;} s = AnnotationConvert (infile, outfile); fclose (infile); fclose (outfile); return s ;} int main () {STA ret = StartConvert (); if (ret = FILE_ERROR) {printf (File error: % d, errno);} else if (ret = FILE_SUCCESS) {printf (converted successfully);} else if (other_error) {printf (other errors: % d, errno);} else {printf (unmatched);} return 0 ;}
  
 
The results in output. c should be as follows:

 

 

// Int I = 0;


// Int y = 0;
Int j = 0;
// Int x = 0;/* 12345678


//
// Int h = 0;
// Int g = 0;
// Int j = 0;
//
Int q = 0;
//
//


//******


/// * 1234567890 */

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.