I have a small problem with char arrays.
I made a function that reverses a char array, which is pretty easy but now I want to also reverse the words.
So if i have char word[] = "hello world"
a call to PrintStringReverse(word) would give me:
dlrow olleh
and a call to PrintWordReverse would give me:Code:void PrintStringReverse(char s[]) { int N = strlen(s); for(int i=0;i<N/2;i++) swap(s[i],s[N-1-i]); cout << s << endl; }
olleh dlrow
How can I go about this using the functions built into <cstring> only, no vector or <string> suggestions please.



LinkBack URL
About LinkBacks


