I'm sure this will be too easy and I'll feel like a stupid fool after a few posts But I'm getting a wee bit ........ed off with myself.
I want to open a file then check to see if the file name is correct and open it. The code compiles ok but always tells me that it can't open the file
Code:
FILE * fptrHistoryFile; //Declares a global file pointer
void main()
{
char HistoryFile[50], rightFile, n, y;
char * pHistoryFileLabel;
do{
puts("Please enter the name of the file that is to be checked e.g History.txt \n");
gets(HistoryFile);
pHistoryFileLabel = HistoryFile; //Assigns a poiter to the file name to be opened.
printf("%s will now be checked. Is this right? \n", pHistoryFileLabel);
puts("enter 'y' to continue or 'n' to input target file again \n");
rightFile = getchar(); //Checks the file name is right.
}while( rightFile == n );
fptrHistoryFile = fopen("pHistoryFileLabel", "r");
if( fptrHistoryFile == 0)
{
puts("An error occured when opening the file ");
exit(1); //Checks the file is valid if not exits the program
}
}
If anyone could throw some advice or suggest something to try i would be VERY grateful Please.
Thanks
Capulet