I’d like to find the number of character in each line using C program. It would work fine if I’m having single statement in a single line. But, if multiple statements means, it adds a 0 following it. How could I modify my code to achieve what I need? Thanks in advance.
fp=fopen("chumma.c","r");
while((c=getc(fp))!=EOF)
{
cn++;
if((c=='\n') || (c==';'))
{
if((cn-1)==0)
em++;
n++;
printf("\nNo. of char in line %d : %d\n",n,(cn-1));
ll[n-1]=cn-1;
cn=0;
}
}
Though the following code seems a little round about, yet it works. If anyone can simplify it, let me know. Thanks.