Code:
char filename[50]={"\0"};
char buffer[100];
FILE *fp;
fgets(filename, sizeof(filename), stdin);
if(filename[strlen(filename)-1]=='\n')
filename[strlen(filename)-1]= '\0'; //remove the newline char
fp=fopen(filename, "rt");
if(fp==NULL) {
printf("\n Error opening %s", filename);
return 1;
}
while((fgets(buffer, sizeof(buffer), fp)) != NULL) {
//do something with buffer which has one row of text
//do something else maybe
}
fclose(fp);
I haven't run the above, but it will be quite close. You'll need to include both stdio.h and string.h.