i have to create a program in c
in which i have to take a file as a input and then seprate the comments from the file and save to new file my code is here #include<stdio.h> #include<stdlib.h> void check_comment (char) ; void block_comment () ; void single_comment () ; FILE *fp,*fp2,*fp3; void main() { char filename[20]; char str; printf("\n enter the file name with path :"); scanf("%s",filename); fp = fopen(filename,"r+"); if(fp==NULL) { printf("\n can't open the file "); exit(0); } printf("\n Enter the filename to open for writing \n"); scanf("%s", filename); fp2 = fopen(filename, "w+"); if (fp2 == NULL) { printf("Cannot open file %s \n", filename); exit(0); } str = fgetc(fp); while (str != EOF) { check_comment(str); str = fgetc(fp); printf("%c",str); } printf("\nContents copied to %s", filename); printf("\n Enter the filename to open for writing \n"); scanf("%s", filename); fp3=fopen(filename,"w+"); fclose(fp); fclose(fp2); fclose(fp3); return 0; } void check_comment(char str) { char d; if( str == '/') { if((d=fgetc(fp))=='*') block_comment(); else if( d == '/') { single_comment(); } else { fputc(str,fp2); } } else fputc(str,fp2); } void single_comment() { char d,e; while((d=fgetc(fp))!=EOF) { fputs(d,fp3); if(d=='\n') return 0; } } void block_comment() { char d,e; while((d=fgetc(fp))!=EOF) { fputc(d,fp3); if(d=='*') { e=fgetc(fp); if(e=='/') return 0; } } }