Hello,
I have a string say,
"My name is John"
I want to reverse it like,
"yM eman si nhoJ"
I wrote a program for it which compiles but doesn't give answer. Can anyone tell me what is the problem in my program. Thanks a lot for all your help
Code:void reverse(char *str){ char * temp = str; char substr[10]; int i = 0, j = 0, k = 0; while(*temp != '\0'){ if(*temp != ' '){ substr[i] = *temp; i++; } else{ if(i>0){ for(j=i; j>0;i--){ *str++ = substr[j]; } *str++ = ' '; k = 1; } } if(k = 1){ i = 0; j = 0; k = 0; } } *str = '\0'; } int main(){ char * text = "My name is John"; cout<<text<<endl; reverse(text); cout<<text; system("PAUSE"); }