-
text file
Hi,
I am writing a program that asks the user to input a file name and the program then reads what is in the file and sends that information to another function. I am a little confused on how to begin. I know the file will contain a string followed by two numbers, but I don't know how many strings there will be.
Like I said I really don't know how to start. Any suggustions would be great.
thanks
-
start here
Code:
#include <stdio.h>
int main()
{
// your code goes here
return 0;
}
you will need a character array of about 255 characers (to hold the longest possible filename) then call fgets() to get the file name from the keyboard. After that, call fopen() to open the file, fgets() to read each line, and finally fclose() to close the file.
Code:
display prompt to enter filename
get filename from keyboard (use fgets() function)
open the file
start of loop
call fgets() to read one line from the file
if fgets() returns NULL then exit the loop
call some other function with line as parameter
end of loop
close file