/* * This program reads a string from the standard input, reverses it, * then prints it */ #include /* swap *a and *b */ void swap (char *a, char *b) { char t; t = *a; *a = *b; *b = t; } /* * Reverse a string. The algorithm: swap the first character with the * last, the second with the next-to-last, etc. up to the middle of * the string. */ void reverse (char s[]) { int i, middle, length; /* length is the length of the string */ length = strlen (s); /* middle is the middle of the string (doesn't matter * if length is even or odd; in the case of an odd length * string, the middle character remains the same */ middle = length / 2; /* swap i'th with length-i-1'th */ for (i=0; i