Hi, I have written a program to reverse words in a string. So if the input is: "My name is Jack", the output should be "yM eman si kcaJ".
But my program is not outputting anything.
Code:
#include <stdio.h>
#include <string.h>
int main(){
char str[100];
char temp[100];
int i, j, k;
int start = 0;
printf("Enter string:");
gets(str);
for (i = 0; i < strlen(str); i++){
if (str[i] == " "){
k = 0;
for (j = start; j < i; j++){
temp[k] = str[j];
k++;
}
temp[k] = '\0';
strrev(temp);
printf("%s", temp);
start = i + 1;
}
}
return 0;
}
Anyone know why my program is not outputting anything?