Re: Newbie problem, fopen
To be absolutely sure, print out the current working directory within the program.
On Linux, it's getcwd() in unistd.h:
http://linux.die.net/man/3/getcwd
On Windows, use _getcwd() in direct.h:
http://msdn.microsoft.com/en-us/library/sf98bd4y.aspx
Sometimes, Windows will hide file extensions so that the name of the file isn't what it appears to be, eg, "hello.txt" may show up in Windows as "hello" but with a text-file icon. In this case if you had called the file "hello.txt", its real name may have been "hello.txt.txt". Make sure this isn't the case; fopen will recognize only exactly identical file names.
Re: Newbie problem, fopen
Well, you were right about the file extensions ...I went through the Windows control panel and displayed all file extensions, so my file was 'open.txt.txt' ...stupid Windows!!
Anyway, when I run the .exe file, the consol window pops up saying 'Didn't open'.
Code:
/* fopen example, exercise 4 */
#include <stdio.h>
int n;
int main ()
{
FILE *pFile;
pFile = fopen ("open.txt.txt","r");
if (pFile!=NULL)
{
printf("Didn't open",pFile); //Display if don't open
fclose (pFile);
scanf("%d%",n); //Used to keep consol open
}
return 0;
}
Seán