用c打开一个TXT文件并读取里面的字符 在读写指定文件时出现错误 请问该如何解决?
include<stdio.h>
include<stdlib.h>
int main(void)
{
FILE *fp;
char str[3][10];
int i = 0;
if ((fp = fopen_s("C:\Users\ASUS\Desktop.txt", "r",10)) == NULL)
{
printf("can't open file!\n");
exit(0);
}
while (fgets(str[i], 10, fp) != NULL)
{
printf("%s", str[i]);
i++;
}
fclose(fp);
return 0;
}
函数用错了,你把 fopen_s 当成 fopen 在用了,它们的参数并不相同。
fopen_s 示例(仅供参考)
fopen 示例(仅供参考)