Convert C language Comments to C + + comments

Source: Internet
Author: User

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

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.