Skip to content

Allow for more than 1000 char input per line for Exercise 1-17 in Chapter 1 #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions chapter_1/exercise_1_17/line_80.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#include <stdio.h>

#define MAXLINE 1000
#define LIMIT 80
#define THRESHOLD 83

int get_line(char line[], int max_line_len);

int main(void)
{
int len;
char line[MAXLINE];

while ((len = get_line(line, MAXLINE)) > 0)
{
if (len > LIMIT)
{
printf("%s", line);
int main(void) {
int len, nextLen;
char first[THRESHOLD];
char continuous[THRESHOLD];

while ((len = get_line(first, THRESHOLD)) > 0) {
if (len == THRESHOLD-1) {
// length contains \n (so +1 to actual count)
printf("%s", first);
nextLen = THRESHOLD-1;

// check if the string terminated at exactly the 81st place by a newline.
// If so, no need to look for new segments of same line input.
if (first[81] != '\n') {
while (nextLen == THRESHOLD-1) {
nextLen = get_line(continuous, THRESHOLD);
printf("%s", continuous);
}
}
}
len = 0;
}
}

return 0;
}

int get_line(char line[], int max_line_len)
Expand Down