I need this question answered to HELP do my homework. I AM NOT asking anyone to do it for me. Say I have the following code: (this is just a function definition at the bottom)(AND the string filename[81] has already been initiated in the main() function)
void get_filename(char filename[81]){
printf("What is the name of the file?\n");
scanf("%s", filename);
}
So far, this function will read in a string that is a filename. I know that I can open a file with the following code at the end of this function:
FILE * input_file;
input_file = fopen("hello.txt","r");
Here is my problem, I need to know how to replace "hello.txt" with the string that the user just entered. (via: the filename[81] string)
I have already tried replacing "hello.txt" with "filename" "&filename" and "filename[ ]"
How would I use the fopen command to open the file specified in the string?
Start Free Trial