欢迎大家关注俺滴公众号“彭睿扬”,分享学习编程心得
C语言里面,大家基本都是使用fopen打开文件的吧?今天使用fopen时出现了不能打开文件的问题。代码如下。
#include <stdio.h>
int writefile(char *filename){
FILE *file = NULL;
file = fopen(filename, "w");
if (file == NULL){
return 1;
}
else{
return 0;
}
}
int main(void){
printf("%d\n", writefile("D:\\程序\\test.txt"));
return 0;
}
运行后输出了1,代表没有成功。改一下文件就成功了。
#include <stdio.h>
int writefile(char *filename){
FILE *file = NULL;
file = fopen(filename, "w");
if (file == NULL){
return 1;
}
else{
return 0;
}
}
int main(void){
printf("%d\n", writefile("D:\\test.txt"));// 这里!
return 0;
}
这个程序就可以成功运行了。得出结论,fopen不支持汉字。
本文探讨了在C语言中遇到fopen函数无法打开含有汉字的文件的常见问题。通过示例代码展示了当文件名包含汉字时,fopen返回失败的情况,并指出fopen可能不支持直接处理汉字路径,建议使用相应编码方式处理文件名。
2811

被折叠的 条评论
为什么被折叠?



