Reading a text file
I have previously posted a question about using code to access a file when the actual name of the file is unknown. the entire name of the text file is stored in a structure component at
file_info[selection].name. I am confused how I should go about opening this file
that portion of my code looks like this thus far.
Can anyone figure out why this won't work? I appreciate your help.
temp = file_info[selection].name;
readfile = fopen(temp,"r");
if(readfile == NULL)
printf("\nfile could not be opened");
printf("\n file was opened");
temp is just a single char. You want a complete string. Assuming that file_info[selection].name is an array or a pointer to a string you can just make temp a pointer and you'll be set:
Or you could avoid the temporary variable altogether by doing this:
readfile = fopen(file_info[selection].name ,"r");
thanks for your help
I realized my mistake as soon as I posted it.
Sometimes I get lost when I stare at code for hours on end