From 93504e6d26987a061484b6bfe86c6affe4019ae2 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 19 Dec 2012 09:16:27 -0600 Subject: Minor cleanups. --- toys/other/rev.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/toys/other/rev.c b/toys/other/rev.c index a95d6615..8cad7da3 100644 --- a/toys/other/rev.c +++ b/toys/other/rev.c @@ -10,7 +10,7 @@ config REV 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 @@ void do_rev(int fd, char *name) 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++; -- cgit v1.2.3