欢迎大家关注俺滴公众号“彭睿扬”,分享学习编程心得
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不支持汉字。