Hi
i'm trying to compile this code, but getting warning. need some help to understand what I'm doing wrong.

void printGraph(FILE *out, GraphRef G){

out = fopen (out, "w");
if( out==NULL ){
printf("Unable to open file %s for writing\n", out);
exit(1);
}
}

warning: passing arg 1 of `fopen' from incompatible pointer type

Recommended Answers

All 2 Replies

Hi
i'm trying to compile this code, but getting warning. need some help to understand what I'm doing wrong.

void printGraph(FILE *out, GraphRef G){

out = fopen (out, "w");
if( out==NULL ){
printf("Unable to open file %s for writing\n", out);
exit(1);
}
}

warning: passing arg 1 of `fopen' from incompatible pointer type

fopen is defined as

FILE* fopen(const char *path, const char *mode);

and you have fopen (out, "w"); where out is FILE*.

Hi
i'm trying to compile this code, but getting warning. need some help to understand what I'm doing wrong.

Instead of

out = fopen (out, "w");

it must be

out = fopen ( filename, "w" );

where filename is a string with the path to the file you want to write.
Remember, when you use the "w" if the file exists it will be overwritten, even if you don't write anything to it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.