C language Comment to C + + comment

Source: Internet
Author: User

Convert C language Comments to C + + annotations

/*......*/turn into//...


Test Case:

1. General Information

/* int a = 0; */


2. Continuous *

/***/


3. Line break issues

/* int b = 0; */int c = 0;

/* AAA */

int d = 0;


4. Matching issues

/*aaa/*bbb*/

/*int e = 0;/*xxxxxx*/


5. Multi-line annotations

/*

Aaa

Bbb

Ccc

*/int AA;


6. Continuous annotation

/*aaa*//*bbb*/


7.c++ Comments (read a line directly after encountering C + + comments)

// /**/

# include<stdio.h># include<stdlib.h>enum tag      {c _begin,c_end,};void convert (const char* fin,char* fout) {File* input = fopen (fin,  "R");if  (null == input) {printf ("Open file%s failed \ n", fIn); return;} File* output = fopen (fout,  "w");if  (null == input) {printf ("Open file%s failed \ n",  fout); return;} Tag tag = c_end;char ch = fgetc (Input);char second;while  (ch !=  eof) {switch  (CH) {case  '/': FPUTC ('/',  output); Second = fgetc (Input);if  ( second ==  ' * ') {//4. Match problem if  (tag == c_end) &NBSP;{FPUTC ('/',  output); tag =  c_begin;} ELSE{FPUTC (' * ',  output);}} else if  (second ==  '/')      // 7.  encountered C + + comment, read line {FPUTC ( Second, output); char cur;do{cur = fgetc (Input);if  (cur == eof) {return;} FPUTC (cur, output);}  while  (cur !=  ' \ n ');} ELSE{FPUTC (second, output);} break;case  ' * ': second = fgetc (Input);if  (second ==  '/'  && tag  == c_begin)    {//  3.  line break char next = fgetc (Input);   (next !=  ' \ n '  && next != eof) {FPUTC (' \ n ',  output); Fseek (Input ,  -1, seek_cur);  //6. Continuous annotation &NBSP;&NBSP;/**//**/}ELSE{FPUTC (next, output);} Tag = c_end;} else                  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//&NBSP;&NBSP;&NBSP;2.&NBSP;/***/&NBSP;{FPUTC (' * ',  Output); Fseek (Input,  -1, seek_cur);} break;case  ' \ n ': fputc (' \ n ',  output);// 5.  multi-line Comment if  (tag == c_begin) {FPUTC ('/') ,  output); FPUTC ('/',  output);} BREAK;DEFAULT:FPUTC (ch, output);} CH&NBSP;=&NBSP;FGETC (Input);} Fclose (Input); fclose (Output);} Void test () {Convert ("Input.cpp", "Output.cpp");} Int main () {Test (); System ("pause"); return 0;}


This article is from the "11356774" blog, please be sure to keep this source http://11366774.blog.51cto.com/11356774/1755435

C language Comment to C + + comment

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.