Welcome to the World of Programming

Welcome to the World of Programming

Search this blog

Reading Comments From C Program

#include<stdio.h>
int main(){
    FILE *fp;
    char a;
    int flag=0;
    fp=fopen("ReadComments.c","r");    //first comment
    a=fgetc(fp);
    while(a!=EOF){
        if(a=='/'){
            a=fgetc(fp);
            if(a=='/'||a=='*'){
                if(a=='/'){
                    while(a!='\n'){
                        a=fgetc(fp);    /*hyuj*/
                        printf("%c",a);
                    }
                }
                if(a=='*'){
                    a=fgetc(fp);
                    while(flag!=1){
                        if(a=='*'){
                            a=fgetc(fp);
                            if(a=='/')
                                flag=1;
                            else
                                printf("*");
                        }
                        if(a!='/')
                            printf("%c",a);
                        a=fgetc(fp);
                    }
                }
            }
        }
        flag=0;
        a=fgetc(fp);
    }
    fclose(fp);
    return 0;
}

No comments:

Post a Comment