Home > Software engineering >  Vc2010 file open always fail?
Vc2010 file open always fail?

Time:10-09

I use vc2010. Write a simple win32 console program to open the file in the program, my machine is Windows 7 64 - bit, open the file is always failure, the program code is as follows:
 int _tmain (int arg c, _TCHAR * argv []) 
{
/* Pointer to the file */
The FILE * fp1=NULL;
/* Character variable to read the content of the file */
char c;

/* Opening a file mode in r */
Fp1=fopen (" myfile. TXT ", "w");

/* Infinite loop - I have 2 break to last come out of the loop */
While (1)
{
C=fgetc (fp1);
If (EOF) c==
break;
The else
Printf (" % c ", c);
}
The fclose (fp1);
return 0;
}

After each debug this one line of code
 fp1=fopen (" myfile. TXT ", "w"); 

File pointer fp1 shows "error pointer", why?
Is related to environmental variation, please help to look at,
Thank you, for many years not write programs on the vc, true don't understand, why such a problem,

CodePudding user response:

First to determine whether a file open success again for later operation

May not find the file, try to use absolute paths

CodePudding user response:

http://en.cppreference.com/w/cpp/io/c/fopen

CodePudding user response:

Successful fopen call??

CodePudding user response:

reference VisualEleven reply: 3/f
fopen call success??

Fopen this will return a pointer to an error, failure,

CodePudding user response:

See the specific error number, whether there is something wrong with the file

CodePudding user response:

reference 5 floor oyljerry reply:
see the specific error number, if there is something wrong with the file

How to get to the error code?

CodePudding user response:

/* Opening a file mode in r */
Fp1=fopen (" myfile. TXT ", "w" ).//??????
  • Related