From 5018e06c580dd21c958ec1672c26a3448faf0c55 Mon Sep 17 00:00:00 2001 From: zlg Date: Wed, 13 Feb 2013 20:48:44 -0600 Subject: Add license file, reorganize project --- 1-19_reverse-lines.c | 54 ---------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 1-19_reverse-lines.c (limited to '1-19_reverse-lines.c') diff --git a/1-19_reverse-lines.c b/1-19_reverse-lines.c deleted file mode 100644 index d87b625..0000000 --- a/1-19_reverse-lines.c +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#define MAXLINELENGTH 9001 - -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. */ -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... - tmp = input[i]; - - // ... and swap! - input[i] = input[size]; - input[size] = tmp; - - // Bring our numbers closer together - ++i; - --size; - } -} - -int main(void) { - // 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); - } - return 0; -} -- cgit v1.2.3-54-g00ecf