I want to print the words of a sentence, given as a string....
But I have a problem with the end of the sentence, and cannot find the bug....
Thanks in advance...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char str[80]="This is a sentence";
int main(){
char *temp;
char *word;
int i;
word=str;
temp=word;
while(temp != NULL){
while(isalpha(*temp)){
temp++;
}//we are in a space character
i=0;
//print the word
while((word+i)!=temp){
printf("%c",(*(word+i)));getchar();
i++;
}
putchar(*temp);getchar();
while(isspace(*temp)&&temp!=NULL) temp++;//search for the next alphanumeric character
word=temp;
printf("*temp=%c %d\n",*temp,*temp);
}
getchar();getchar();
return 0;
}