Am tyring to solve simple string related problem.Its almost solve but i faced some problem and can't understand.so i need your help for get my soluton .
here is my coding
Code:
#include<stdio.h>
#include<string.h>
int main()
{
// freopen("ic.txt","r",stdin);
char a[200];
int i,j=0,l,c=0,k=0;
while(fgets(a,sizeof(a),stdin)!=EOF)
{
l=strlen(a);
for(i=0;i<l-1;i++)
{
//printf("%d ",i);
//j=i;
if((a[0]==32)||(a[0]==',')||(a[0]=='.'))
{
k++;
while((a[k]==32)||(a[k]==',')||(a[k]=='.'))
{
//i++;
k++;
}
i=k;
}
if((a[i+1]==32)||(a[i+1]==',')||(a[i+1]=='.'))
{
c++;
//j++;
while((a[i+1]==32)||(a[i+1]==',')||(a[i+1]=='.'))
{
i++;
//j++;
}
}
}
printf("\n%d %d %d\n",(c+1),k,i);
c=k=0;
//puts(a);
}
}
problem 1
here i got warning for using EOF. i dont know why i waring.
/media/sda9/c partice/string/word-count.c||In function ‘main’:|
/media/sda9/c partice/string/word-count.c|7|warning: comparison between pointer and integer [enabled by default]|
||=== Build finished: 0 errors, 1 warnings ===|
how i solve this warning?
problem number 2
if i took my input these[space or . or ,]
then i got k value (i-1)
i dont know why.
here is simple input
Code:
...raihan...,, riya,,,...hmmm
simple output
here i got k=(i-1)
but how?
pls everybody debug my code and tell me any more error.