Code:
int main(int argc, const char * argv[]) {
char str[79];
char reverse[79][79];
char *ptr;
int i = 0;
printf("Input: ");
fgets(str,79,stdin);
ptr = strtok(str," ");
while (ptr !=NULL){
strcpy(reverse[i],ptr);
i++;
ptr = strtok(NULL," ");
}
for(i=2;i>=0;i--) {
printf(" %s",reverse[i]);
}
return 0;
}
Basically my program will reverse words.
for example
input:bees and birds
output: birds and bees
However, somehow my for loop skips a line after i=0
input: birds and bees
output: birds <------ After 1st world, a line is skipped for no reason.
andbees
how does this happen? it seems impossible.