C examples for String:String Function
Reverse string s in place
#include <stdio.h> #include <string.h> #include <string.h> /* reverse: reverse string s in place */ void reverse2(char s[]) { int c, i, j;/* ww w . ja va 2s.c o m*/ for (i = 0, j = strlen(s)-1; i < j; i++, j--) c = s[i], s[i] = s[j], s[j] = c; } int main(){ char buf[1000], buf1[1000]; while (fgets(buf, sizeof buf, stdin) != NULL) { strcpy(buf1, buf); reverse2(buf1); reverse2(buf1); if (strcmp(buf, buf1) != 0) printf("botch2 on %s\n", buf); } return 0; }