Mercurial > hg > toybox
diff toys/other/rev.c @ 754:06c32155cb95
Minor cleanups.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 19 Dec 2012 09:16:27 -0600 |
parents | 7d258f3c13dc |
children | c42f64ea297d |
line wrap: on
line diff
--- a/toys/other/rev.c Sun Dec 16 12:31:15 2012 +0100 +++ b/toys/other/rev.c Wed Dec 19 09:16:27 2012 -0600 @@ -10,7 +10,7 @@ help usage: rev [FILE...] - Output lines reversed, when no files are given stdin is used. + Output each line reversed, when no files are given stdin is used. */ #include "toys.h" @@ -20,15 +20,13 @@ char *c; for (;;) { - int len; - int i; + int len, i; + if (!(c = get_line(fd))) break; len = strlen(c) - 1; - i = 0; - while ( i <= len/2) - { - char tmp; - tmp = c[i]; + for (i = 0; i <= len/2; i++) { + char tmp = c[i]; + c[i] = c[len-i]; c[len-i] = tmp; i++;