How to read a file line-by-line in C?
问题 I have a text file with up to 100 IP addresses, 1 per line. I need to read each address, as a string, into an array called "list". First, I'm assuming that "list" will need to be a two-dimensional char array. Each IP address is 11 characters in length, 12 if you include '\0', so I declared list as follows: char list[100][12]; Next, I attempt to use fgets to read the stream: for (i = 0; i < 100; i++) { if (feof(stream)) break; for (j = 0; j < 12; j++) fgets(&list[i][j], 12, stream); count++; }