I was reading and couldn't figure out how to properly do this.
I have a main.c that can't be changed, I'm given a char array char fn[MAX]; max is 100. It is passed into a function readFileName(fn); This is where I get user input to get a new file name. Every time I run my function I get a segmentation fault(core dumped) error. This is what my function looks like. Obviously I'm doing it wrong, but I'm not sure why. Do I need to make a pointer somewhere? Any help would be much appreciated.
void readFileName(char fn[]){
printf("Please enter the new file that you would like to open\n");
scanf("%s", fn);
printf("%s", fn);
}
This is the beginning of the program
int main(int argc, char *argv[]){
int month, choice;
int * temps;
FILE * fin = NULL;
char fn[MAX];
fin = openFile(argc, argv);
month = readMonth(fin);
temps = fillArray(month, fin);
This is towards the end of the program
fclose(fin);
fin = NULL;
cleanUp(temps);
temps = NULL;
readFileName(fn);
// fin = openInputFile(fn);
month = readMonth(fin);
temps = fillArray(month, fin);
fnthat you pass in the function call?char fn[MAX]is a global that's never used? Can you show us how you call the functionreadFileName? Also, try checking the return value ofscanf.char fn[MAX]and then when we call the function it isreadFileName(fn)