Hi, i keep getting a segmentation fault and i cannot figure where the problem is, well the problem is in the while loop but not sure what is wrong with it.
Question is enter a line of words with spaces then tokenize them and print in reverse.
Here is the code:
#include<stdio.h>
#include<string.h>
void main ()
{
char sentense[100]="\0";
char tokens[25][20];
char *sptr;
int i=0,j=0,t;
printf ("Enter a line of text:\n", sentense);
fgets (sentense, 99, stdin);
//printf ("\n%s", sentense);
sptr=strtok(sentense, " ");
strcpy(tokens[i],sptr);
printf ("%s\n", tokens[i]);
i=1;
while (sptr!=NULL)
{
sptr=(NULL, " ");
strcpy(tokens[i],sptr);
i++;
//printf ("\n%s", tokens[i]);
}
printf ("\n");
for (t=i-1; t>=0; t--)
{
printf ("%s ", tokens[t]);
}
}
Any help would be appriciated.