Created
October 25, 2014 04:52
-
-
Save keyboardspecialist/8905feeee8f4b6c626d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void wordrev(char* str) | |
{ | |
char *p, *r, *tp, *ip; | |
p = str; | |
tp = strchr(str, ' '); | |
r = ip = !tp ? p + strlen(str)-1 : (tp==p ? tp : tp-1); | |
while(1) | |
{ | |
for(; p < r; p++, r--) | |
*r ^= *p, *p ^= *r, *r ^= *p; | |
if(*++ip == '\0') | |
break; | |
p = tp+1; | |
tp = strchr(tp+1, ' '); | |
r = !tp ? r + strlen(r)-1 : tp - 1; | |
ip = r; | |
} | |
} | |
int main() | |
{ | |
char str[] = " what the fuck gh a i sldfkj moonbase7"; | |
wordrev(str); | |
puts(str); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment