user1543915
user1543915

Reputation: 1045

Fopen a file in C

This is my code :

outfile = fopen(outname, "w");//outname="/home/user/dir/file"
if (!outfile) {
printf("There was a problem opening %s for writing\n", outname);
}
else {
 /* write to the file, */
 }

at run it display: There was a problem opening /home/user/dir/file for writing Please i ask if you have an idea about this error Thank you.

Upvotes: 0

Views: 164

Answers (1)

pmg
pmg

Reputation: 108968

Try perror() for a better description of the error.

if (!outfile) {
    /* printf("There was a problem opening %s for writing\n", outname); */
    perror(outname);
}

Upvotes: 5

Related Questions