I am trying to write a c++ code that reverse a string by the user . ex :
the user enters "apple and orange"
.
the output is "orange and apple"
.
#include <stdio.h>
#include <string.h>
int main(void) {
char str[100];
char delims[] = " ";
char *token;
printf("enter your word seperated by space ");
gets(str);
token = strtok( str, delims );
while ( token != NULL ) {
printf( " %s\n", token);
token = strtok( NULL, delims );
}
system("pause");
return 0;
}
Q : how can I swap the first and the last word ? Thanks.