c++註釋


#include<stdio.h>            

#include<stdlib.h>               

#include<assert.h>               

#include<string.h>

                    

char *get_str(char *src,char *dst)              

{              

    char *start=src;          

    static int count=0;          

    int i=0;          

    while ( *start)          

    {          

        if (*start=='/'&&*(start+1)=='/'&&count%2==0)     

        {      

            count++;   

            break; 

        }      

        else if(*start=='*'&&*(start+1)=='/')     

        {      

            start+=2;  

            count++;   

            break; 

        }      

        *(dst++)=*(start++);       

    }          

    *dst=0;        

    return start;         

}              

        //註釋與代碼混合時的例子      

 void fun2()             

{              

    char src[]="//999*/666//999*/534643666//";        

    char dst[10];         

    char *arr=src;        

    while(*arr)        

    {          

       arr=get_str(arr,dst);        

       printf("%s\n",dst);          

    }          

                

}              

   //註釋多行時的處理。    

                 

int main()            

{              

    FILE *fr=fopen("in.txt","rb");        

    FILE *fw=fopen("out.txt","wb");           

        //assert(fr!=NULL);            

    //assert(fw!=NULL);        

    char start[50];          

    char arr[100]="//";           

    char *str=NULL;           

    int count=0;          

    int n=0;          

    while( fgets(start,100,fr)!=NULL)         

    {          

        str=start;     

        while(*str)    

        {      

            if(*str=='/'&&*(str+1)=='*')   

            {  

                *(str+1)='/';

                count=1;

            }  

            if(*str=='*'&&*(str+1)=='/'&&count==1) 

            {  

                *str=0;

                strcat(arr,start);

                fputs(arr,fw);

                count=0;

                break;

            }  

            str++; 

        }      

        n++;       

        if(count==1&&n==1)     

        {      

            fputs(start,fw);   

        }      

        else if(count==1&&n!=1)       

        {      

            strcat(arr,start); 

            fputs(arr,fw); 

            arr[2]=0;  

        }      

                 

    }          

    fclose(fr);        

    fclose(fw);        

      

  return 0;         

}      

//項目沒有合併好,對於最重要的2種情況,能分別處理,而合併互相有影響


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章