| io/non-blank-lines.c - Et program der læser ikke-blanke liner fra en fil og udskriver disse på standard output. | Lektion 13 - slide 24 : 32 Program 1 |
#include <stdio.h>
#define LINE_MAX 300
int main(int argc, char *argv[]){
FILE *ifp = fopen(argv[1],"r");
int i = 0;
char line[LINE_MAX];
while (fscanf(ifp," %[^\n]", line) == 1){
/* Space: Skip white space. */
/* The space is very important for this example. */
/* Then scan until (but not including) new line. */
printf("%s\n", line);
i++;
}
printf("\n i: %d\n", i);
fclose(ifp);
return 0;
}