0

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.

user1543915
  • 1,025
  • 1
  • 10
  • 16

1 Answers1

5

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

if (!outfile) {
    /* printf("There was a problem opening %s for writing\n", outname); */
    perror(outname);
}
pmg
  • 106,608
  • 13
  • 126
  • 198
  • i have this message fopen: No such file or directory, please how can verify if a directory exist on Linux (with C)? – user1543915 Sep 20 '12 at 10:24
  • Use access, see eg [this SO question and answers](http://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c-cross-platform). – pmg Sep 20 '12 at 17:16