Skip to content

Commit

Permalink
increase maximum line length to 16 * LINE_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Jun 15, 2015
1 parent 9bcc9da commit bad6a81
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions filterline.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string.h>

static const char *PROGRAM_VERSION = "0.1.0";
// TODO(miku): allow this to set via env
static const int MAX_LINE_LENGTH = LINE_MAX * 16;

int main (int argc, char *argv[]) {

Expand All @@ -13,7 +15,7 @@ int main (int argc, char *argv[]) {

unsigned int to_print;
unsigned int current = 0;
char line[LINE_MAX];
char line[MAX_LINE_LENGTH];

char *VERSION = "-v";

Expand All @@ -25,6 +27,7 @@ int main (int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s FILE1 FILE2\n\n", argv[0]);
printf("FILE1: line numbers, FILE2: input file\n");
printf("MAX_LINE_LENGTH=%d\n", MAX_LINE_LENGTH);
return 0;
}

Expand All @@ -35,7 +38,7 @@ int main (int argc, char *argv[]) {
return 1;
} else {
while (fscanf(L, "%u", &to_print) > 0) {
while (fgets(line, LINE_MAX, F) != NULL && ++current != to_print);
while (fgets(line, MAX_LINE_LENGTH, F) != NULL && ++current != to_print);
if (current == to_print) {
printf("%s", line);
}
Expand Down

0 comments on commit bad6a81

Please sign in to comment.