summaryrefslogtreecommitdiff
path: root/longest_line.c
diff options
context:
space:
mode:
authorAdam Carpenter <gitlab@53hor.net>2019-07-09 16:00:48 -0400
committerAdam Carpenter <gitlab@53hor.net>2019-07-09 16:00:48 -0400
commit39c0cbcc70aff47e17107826aa76cb525c83b122 (patch)
treedf483af220a11aab49e0e3a76eea54f60efbd424 /longest_line.c
parent583fc81152e120ec5873f8057f11a894bb8b0a91 (diff)
downloadlearning-c-39c0cbcc70aff47e17107826aa76cb525c83b122.tar.xz
learning-c-39c0cbcc70aff47e17107826aa76cb525c83b122.zip
ch2
Diffstat (limited to 'longest_line.c')
-rw-r--r--longest_line.c58
1 files changed, 0 insertions, 58 deletions
diff --git a/longest_line.c b/longest_line.c
deleted file mode 100644
index 58f2a72..0000000
--- a/longest_line.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include<stdio.h>
-#define MAXLENGTH 1000
-
-int get_line(char line[], int maxlength);
-void copy(char to[], char from[]);
-
-/*
- * MAIN
- * Prints longest line in STDIN.
- */
-main() {
- int len; // current line length
- int max; // maximum length seen so far
- char line[MAXLENGTH]; // current input line
- char longest[MAXLENGTH]; // longest line saved here
-
- max = 0;
- while ((len = get_line(line, MAXLENGTH)) > 0)
- if (len > max) {
- max = len;
- copy(longest, line);
- }
- if (max > 0) // there was a line
- printf("%d\t", max);
- printf("%s", longest);
- return 0;
-}
-
-/*
- * GET_LINE
- * Read STDIN into LINE up to MAXLENGTH and return its length.
- * Returns the length of a the line.
- */
-int get_line(char line[], int maxlength) {
- int c, i;
-
- for (i = 0; i < maxlength - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
- line[i] = c;
- if (c == '\n') {
- line[i] = c;
- ++i;
- }
- line[i] = '\0';
- return i;
-}
-
-/*
- * COPY
- * Copy FROM into TO; assume TO is big enough.
- */
-void copy(char to[], char from[]) {
- int i;
-
- i = 0;
- while ((to[i] = from[i]) != '\0')
- ++i;
-}
-