Hello everyone. I am a little stuck on my project that I am working on. I am almost done, but this save file is the problem. I have to give the user an option to save what their results of the program to the save file, which is what I am trying to do. It's just not coming out? Here is my code (which is only of the save method. In my program, the prototype and call from the main function is also there):
Code:
void save_file()
{
char filename;
char option[5];
printf("Would you like to save a file of this data?");
printf("Enter Yes or No: ");
scanf("%c", option);
if (option == Yes)
{
FILE *outfile = fopen(filename, "w");
if(outfile == NULL)
{
printf( "The File was not successfully open.\n ");
return -1;
}
fclose(outfile);
}
else
{
printf("No save file will be written\n");
}
}
These are the errors I am getting:
Code:
ProjectTest2.c: In function âsave_fileâ:
ProjectTest2.c:87: error: âYesâ undeclared (first use in this function)
ProjectTest2.c:87: error: (Each undeclared identifier is reported only once
ProjectTest2.c:87: error: for each function it appears in.)
ProjectTest2.c:89: warning: passing argument 1 of âfopenâ makes pointer from integer without a cast
/usr/include/stdio.h:271: note: expected âconst char * __restrict__â but argument is of type âcharâ
ProjectTest2.c:93: warning: âreturnâ with a value, in function returning void
I have never had to write a file before, only had to open/read. So, I hope I am even doing this correctly? I am also unsure of my use of a void (the compiler sure doesn't seem happy about it), but I am unsure of what else to use? Is it even appropriate to be doing a save in a function (the only reason I did it was because my instructor wants the maximum use of functions)? Any guidance at all would be awesome!
Thank you!