aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/rev.c14
1 files 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++;