6

私は 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

何かご意見は?御時間ありがとうございます。

4

3 に答える 3