My printf is showing null ! May be I'm not being clear:
Say I've an i/p as :
1 2 3
1 2 4
2 3 4
separated by spaces and \n s.
Now I use Dave's code as:
Code:
/*s is a single line i/p say 1 2 3 */
while(fgets(s,1000,f)!=NULL)
{
char *token=s;
char *buffer;
int i,n;
printf("line %d:\n",++k);
for(i=0;*token;i++)
{
size_t len= strcspn(token," \n");
n = sprintf(buffer,"token[%2d] = %*.*s\n", i, (int)len, (int)len, token");
printf ("[%s] is a %d chars string\n",buffer,n);
token+=len+1 ;
}
}
I'm getting buffer as null.Is my syntax correct? Also what I want is after first iteration of while loop buffer should be as buffer[0]=1, buffer[1]=2 and buffer[2]=3.
Thanks,
Angshu