Hello,
I'm having a bit of trouble opening a user specified file in C. When I execute my code, it will not open the file, even though the files are in the same directory. I have even added them under the Resources folder.
I'm working in Visual Studio 2010. I remember someone told me I had to change some settings for it work, but I cannot remember what it was. The settings are default.
Anyway here's my code:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
int main()
{
char fname[10]; //spreadsheet
printf("Please enter the name of the SPREADSHEET you want to use: ");
fflush(stdin);
gets(fname);
FILE *fp;
if ((fp=fopen(fname, "r")) == NULL)
{
printf("\nCannot open file");
getch();
exit(1);
}
fclose(fp);
return 0;
}
Any help would greatly be appreciated. If you've had this problem before, and even the slightest adjustment made it work, please share it! Thanks.