我用vc2010编写一个简单的win32控制台程序,在程序中打开文件,我的机器是win7 64位。打开文件总是失败的,程序代码如下图:
int _tmain(int argc, _TCHAR* argv[])
{
/* Pointer to the file */
FILE *fp1=NULL;
/* Character variable to read the content of file */
char c; /* Opening a file in r mode*/
fp1= fopen ("myfile.txt", "w"); /* Infinite loop –I have used break to come out of the loop*/
while(1)
{
c = fgetc(fp1);
if(c==EOF)
break;
else
printf("%c", c);
}
fclose(fp1);
return 0;
}
每次调试这一行代码后
fp1= fopen ("myfile.txt", "w");
文件指针fp1显示“错误指针”,为什么?
是不是和变异环境有关系,请大家帮忙看看。
谢谢大家,好多年没在vc上写程序了,真搞不明白,为什么会出这样的问题。
int _tmain(int argc, _TCHAR* argv[])
{
/* Pointer to the file */
FILE *fp1=NULL;
/* Character variable to read the content of file */
char c; /* Opening a file in r mode*/
fp1= fopen ("myfile.txt", "w"); /* Infinite loop –I have used break to come out of the loop*/
while(1)
{
c = fgetc(fp1);
if(c==EOF)
break;
else
printf("%c", c);
}
fclose(fp1);
return 0;
}
每次调试这一行代码后
fp1= fopen ("myfile.txt", "w");
文件指针fp1显示“错误指针”,为什么?
是不是和变异环境有关系,请大家帮忙看看。
谢谢大家,好多年没在vc上写程序了,真搞不明白,为什么会出这样的问题。
fp1= fopen ("myfile.txt", "w"); // ????