Annotation conversion (Part)

Source: Internet
Author: User

Annotation conversion (Part)

# Include
 
  
# Include
  
   
# Include typedef enum STATE {SUCCESS, // FILE_ERROE is successful, // file error NO_MATCH, // does not match OTHER, // OTHER error} STATE; typedef enum TAG {TAG_BEGIN, // TAG_END in the C Comment Segment, // C comment end} TAG; # pragma warning (disable: 4996) STATE AnnotationConvert (FILE * inFile, FILE * outFile) {TAG tag = TAG_END; char firstCh, secondCh; 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_BEGIN;} else {fputc (firstCh, outFile); fputc (secondCh, outFile); if (secondCh = '/') {char next = fgetc (inFile); while (next! = '\ N') {next = fgetc (inFile); fputc (next, outFile) ;}} break; case' \ N': fputc ('\ n ', outFile); if (tag = TAG_BEGIN) {fputc ('/', outFile); fputc ('/', outFile);} break; case '*': secondCh = fgetc (inFile); if (secondCh = '/' & tag = TAG_BEGIN) {char next = fgetc (inFile); if (next! = '\ N' & next! = EOF) {fputc ('\ n', outFile); fseek (inFile,-1, SEEK_CUR) ;}if (next = EOF) {firstCh = EOF ;} tag = TAG_END;} else {fputc (firstCh, outFile); fseek (inFile,-1, SEEK_CUR);} break; default: fputc (firstCh, outFile); break ;}} while (firstCh! = EOF); if (tag = TAG_END) {return SUCCESS;} else {return NO_MATCH;} int StartConvert () {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) {return FILE_ERROE;} if (outFile = NULL) {fclose (inFile); return FILE_ERROE;} s = AnnotationConvert (inFile, outFile); fclose (inFile ); fclose (outFile); return s;} int main () {STATE ret = StartConvert (); if (ret = SUCCESS) {printf ("converted successfully \ n ");} else if (ret = NO_MATCH) {printf ("unmatched \ n");} else if (ret = FILE_ERROE) {printf ("file error: % d \ n ", errno);} else {printf (" other errors: % d \ n ", errno);} return 0 ;}
  
 

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.