[C Language] C language annotation is converted into C ++ annotation ., Note

Source: Internet
Author: User

[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

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.