Concept

How can you read a text file one line at a time?

ComputerScienceOne / Binary Files

"22. File I/O\n\n4 //read the first line\n\n5 char *s = fgets(line, 1000, input);\n\n6 while(s != NULL) {\n\n7\n\n8 //chomp the endline character from line:\n\n9 line[strlen(line)-1] = '\\0';\n\n10\n\n11 //process the current buffer\n\n12 //for demonstration, we simply print it:\n\n13 printf(\"line = %s\n\n\", line);\n\n14\n\n15 //read the next line\n\n16 s = fgets(line, 1000, input);\n\n17 }\n\nA similar function, int fgetc(FILE *stream) allows us to get a single character from the input file (returned as an int ) if we prefer to read character by character."

Related Ideas