/ Published in: C
Expand |
Embed | Plain Text
// Ansi string only! void reverse(char* s) { // Get the length of the string int len = 0; char* p = s; while (*p != 0) { len++; p++; } // Swap ... int i = 0; char c; while (i <= len / 2 - 1) { c = *(s + i); *(s + i) = *(s + len - 1 - i); *(s + len - 1 - i) = c; i++; } } int main() { char s[] = "Hello World!"; reverse(s); return 0; }
You need to login to post a comment.
