我正在学习 C,我来自 Java 背景。如果我能得到一些指导,我将不胜感激。这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
char *str = "test text\n";
FILE *fp;
fp = fopen("test.txt", "a");
write(fp, str);
}
void write(FILE *fp, char *str)
{
fprintf(fp, "%s", str);
}
当我尝试编译时,我收到此错误:
xxxx.c: In function ‘main’:
xxxx.c:18: warning: passing argument 1 of ‘write’ makes integer from pointer without a cast
/usr/include/unistd.h:363: note: expected ‘int’ but argument is of type ‘struct FILE *’
xxxx.c:18: error: too few arguments to function ‘write’
xxxx.c: At top level:
xxxx.c:21: error: conflicting types for ‘write’
/usr/include/unistd.h:363: note: previous declaration of ‘write’ was here
有什么想法吗?谢谢你的时间。