/** * reverser - a program that reverses its imput lines */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include // For printf and gets and such. #include // For strchr #include "string-utils.h" // For string_reverse // +-----------+------------------------------------------------------ // | Constants | // +-----------+ /** * The maximum number of characters per line. */ #define LINE_WIDTH 128 // +------+----------------------------------------------------------- // | Main | // +------+ int main () { char line[LINE_WIDTH+2]; // One line of text: line width + newline + \0 // LINE_WIDTH would also be acceptable. // Repeatedly read lines, drop the newline, reverse, and print. while (fgets (line, LINE_WIDTH+1, stdin) != NULL) { char *eol = strchr (line, '\n'); if (eol != NULL) *eol = '\0'; string_reverse (line); printf ("%s\n", line); } // And we're done return 0; } // main