// readlines.c // reads and displays lines from a file #include int main (int argc, char** argv) { int i = 0; int line = 1; char c; char buff [128]; FILE* f = fopen(argv[1],"r"); // open file named in argv[1] for reading while ((c = fgetc(f)) != EOF) { // EOF is "end of file" marker if (i >= 128) { printf("buffer overflow!\n"); exit(0); // abort program if buffer overflow; // there are security problems if this not done! } else if (c == '\n') { buff[i] = 0; printf("%d:\t%s\n", line, buff); i = 0; line++; } else { buff[i++] = c; } } }