如何解决fopen() 总是返回 0x0
我正在尝试打开一个文本文件并逐个字符地读取它。 这是我的代码:
printf( "Opening the file test.txt in read mode" ) ;
fp = fopen ( "test.txt","r" ) ; // opening an existing file
if ( fp == NULL )
{
printf ( "Could not open file test.txt" ) ;
return 1;
}
printf( "Reading the file test.txt" ) ;
while ( 1 )
{
c = fgetc ( fp ) ; // reading the file
if ( c == EOF )
break ;
printf ( "%c",c ) ;
}
printf("Closing the file test.txt") ;
fclose ( fp ) ; // Closing the file
文件 test.txt 与程序 (exe) 存在于同一目录中。
当我执行它时,fopen() 总是返回 NULL。有人可以帮助我,可能有什么问题吗? 谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。