From f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 Mon Sep 17 00:00:00 2001 From: zlg Date: Thu, 16 Jun 2016 10:15:33 -0700 Subject: The massive astyle sweep! Code style should be consistent now. All future commits will be run through astyle or they will be amended. --- ch1/1-19_reverse-lines.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'ch1/1-19_reverse-lines.c') diff --git a/ch1/1-19_reverse-lines.c b/ch1/1-19_reverse-lines.c index f92c6fa..4bb83d9 100644 --- a/ch1/1-19_reverse-lines.c +++ b/ch1/1-19_reverse-lines.c @@ -23,20 +23,16 @@ int get_line(char s[], int limit) { int c, i; - for (i = 0; i < limit && (c = getchar()) != EOF && c != '\n'; ++i) { s[i] = c; } - s[i] = '\0'; - /* If I don't include this check, I can't handle blank lines */ if (c == EOF && i == 0) { return -1; } else { return i; } - } /* Directly reverse a line's contents. */ @@ -44,27 +40,23 @@ void reverse(char input[], int size) { int tmp; int i = 0; size--; - /* If len and i are the same, then there's no reason to proceed */ while (size > i) { - // Store the first character in a temporary spot... + /* Store the first character in a temporary spot... */ tmp = input[i]; - - // ... and swap! + /* ... and swap! */ input[i] = input[size]; input[size] = tmp; - - // Bring our numbers closer together + /* Bring our numbers closer together */ ++i; --size; } } int main(void) { - // An int and a string to store each line's data in + /* An int and a string to store each line's data in */ int line_len; char buffer[MAXLINELENGTH]; - while ((line_len = get_line(buffer, MAXLINELENGTH)) != -1) { reverse(buffer, line_len); printf("%s\n", buffer); -- cgit v1.2.3-54-g00ecf