Code :
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *f1,*f2;
f1=fopen("input.c","r");
f2=fopen("output.txt","w");
char ch=fgetc(f1);
int count=1;
while(ch!=EOF)
{
if(ch=='\n')
{
count++;
}
if(ch=='/')
{
ch=fgetc(f1);
if(ch=='/')
{
fprintf(f2,"\nSingle
line comment at line %d",count);
}
else
if(ch=='*')
{
fprintf(f2,"\nMultiple
line comment start at line %d",count);
ch=fgetc(f1);
while(ch!='*')
{
if(ch=='\n')
{
count++;
}
ch=fgetc(f1);
}
if(ch=='*')
{
ch=fgetc(f1);
if(ch=='/')
{
fprintf(f2,"
and end at line %d",count);
}
}
}
}
ch=fgetc(f1);
}
printf("Check
the output in outpt.txt");
return 0;
}
No comments:
Post a Comment