int main()
{
char c1,c2,src[30],dest[30];
FILE *fsrc,*fdest;
/*Accept names of source and destination files */
printf("Enter the names of source and destination files:\n");
scanf("%s %s",src,dest);
/*opening source file */
fsrc=fopen(src,"r");
if(fsrc==NULL)
{
printf("Source file cannot be opened");
return 0;
}
/*opening destination file */
fdest=fopen(dest,"w");
if(fdest==NULL)
{
printf("Destination file cannot be opened");
return 0;
}
while((c1=getc(fsrc))!=EOF)
{
/*earch begining of a comment by / and store in c1 */
if(c1=='/')
{
/*search b* and store in c2 */
if((c2=getc(fsrc))=='*')
{
while(1)
{
/*search for * */
if((c1=fgetc(fsrc))=='*')
{
/*search for / */
if((c1=fgetc(fsrc))=='/')
break;
}
}
}
else
{
putc(c1,fdest);
putc(c2,fdest);
}
}
else
{
putc(c1,fdest);
}
}
printf("Source file copied to destination after removing the comments.\n");
/*closing files*/
fclose(fsrc);
fclose(fdest);
return 0;
}
0 comments: