Need help opening a user provided file
Hi everyone,
This is my first real attempt at file i/o stuff in C. The user should be able to choose whether to import the provided file or their own file, and I was able to open the provided file.
The problem arises when they choose to import their own file (when the argument "provided" is false). They don't even get to enter the filename before a segmentation fault occurs. What's wrong with the way I did this?
Code:
void import(bool provided) {
String filename;
FILE *f = fopen(provided? "Lab6-Data.csv": fgets(filename, 50, stdin), "r");
putchar(fgetc(f));
fclose(f);
}
P.S. I used a typedef to rename 'char *' to String, I am using C.