/* EXERCISE 4-13 */ #include <stdio.h> #include <ctype.h> #define MAXLINE 100 int getline(char [], int); void reverse(char []); main() { char line[MAXLINE]; /* INPUT LINE AREA */ printf("ENTER STRING\n"); if (getline(line, MAXLINE) <= 0) { printf("\nNO DATA ENTERED\n"); return 0; } else { reverse(line); printf("\nTHE REVERSED STRING IS: %s\n", line); } printf("\nEND OF PROGRAM\n"); return 0; } /* GETLINE: GET LINE INTO s , RETURN LENGTH */ int getline(char s[], int lim) { int c, i; i = 0; while (--lim > 0 && (c=getchar()) != EOF && c != '\n') s[i++] = c; if (c == '\n') s[i++] = c; s[i] = '\0'; return i; } /* REVERSE: REVERSE A STRING IN PLACE */ /* RECURSIVE VERSION */ void reverse(char s[]) { static int i = 0; static int j = 0; int c; if (s[i] == '\0') return; c = s[i++]; reverse(s); s[j++] = c; }