Tuesday 24 July 2012

remove all the comments from a C

/*Program to remove all the comments from a C program*/

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;

}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: