0

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

Edited by hosh: n/a

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Aia
0

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*.

Edited by gerard4143: n/a

1

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.

Edited by Aia: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.