8
I am learning C and I come from a Java background. I would appreciate it if I could have some guidance. Here is my code:
#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);
}
When I try to compile, I get this error:
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
Any thoughts? Thanks for your time.