Skip to content

Instantly share code, notes, and snippets.

@keyboardspecialist
Created October 25, 2014 04:52
Show Gist options
  • Save keyboardspecialist/8905feeee8f4b6c626d6 to your computer and use it in GitHub Desktop.
Save keyboardspecialist/8905feeee8f4b6c626d6 to your computer and use it in GitHub Desktop.
#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