hi i am trying to read data from a file which is arranged as follows
item1
item2
item3
etc
etc
etc
i am trying to read this then reproduce it on the console window line by line i have only been able to scan it all then display it all in one line in the console but i need to reproduce it line by line
here is the code im using is there a way i can change it do do this? i am very new to c.
the "if f(open) = fail" bit i stole straight out a text book by the way
Code:#include <stdio.h> #include <unistd.h> int main(void) { int i; FILE *fp; if ((fp=fopen("datafile", "r")) == NULL) { fprintf(stderr, "Failed to open file\n"); exit(1); } else { { char input[1000]; rewind(fp); do { i = fscanf(fp, "%s", input); printf("%s\n", input); } while(i !=EOF); } fclose(fp); } return 0; }



LinkBack URL
About LinkBacks


