这是在文件中写入内容的代码。
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
FILE *fp;
char ch(90);
fp = fopen("books.txt","w");
if(fp == NULL)
{
puts("Cannot open file");
}
printf("Enter lines of text:");
while(strlen(gets(ch)) > 0)
{
fputs(ch, fp);
}
fclose(fp);
}
我收到 4 个错误。这些是:
- Cannot convert
int
tochar *
in functionmain()
.- Type mismatch in parameter
__s
in call togets(char *)
in functionmain()
.- Cannot convert
int
toconst char *
in functionmain()
.- Type mismatch in parameter
__s
in call tofputs(const char *,FILE *)
in functionmain()
.
最佳答案
我相信你对 char 数组的定义是错误的:
char ch(90);
必须是
char ch[90];
关于c - 无法写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30343598/