Skip to content

Instantly share code, notes, and snippets.

@kavu
Created January 26, 2011 14:25
Show Gist options
  • Save kavu/796750 to your computer and use it in GitHub Desktop.
Save kavu/796750 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static char buf[] = "the world helorow";
static void revstr(char *start, char *end) {
register char temp;
while(start < end) {
temp = *start;
*start++ = *end;
*end-- = temp;
}
}
int main(int argc, char **argv) {
register char *end, *x, *y;
printf("Original string --- %s\n",buf);
end = &buf[strlen(buf)];
revstr(buf,end-1);
printf ("Reversed --- %s\n",buf);
x = y = buf;
while(x++ < end) {
if(/* !isalnum(*x) || */ isspace(*x) || iscntrl(*x)) {
revstr(y,x-1);
y = x+1;
}
}
printf("Processed string --- %s\n",buf);
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment