0
FILE * f = fopen("c:\\out.txt", "wb"); if(f == NULL) printf("ERR"); 

This code prints ERR. c:\out.txt does not yet exist. However if I create an empty file called out.txt and then place in the c:\ the code executes fine. How do I make c create a file if it does not exist?

9
  • 8
    Run your program as Administrator. You probably don't have permissions to create files at c:\\ Commented Dec 28, 2013 at 17:08
  • 1
    could you try w+ instead of wb. you could also try calling fclose. at the end of the program. Commented Dec 28, 2013 at 17:08
  • 1
    @KirillKulakov: It's not clear how either of those would help here... Commented Dec 28, 2013 at 17:14
  • 5
    Print out the value of errno when fopen fails to determine what the problem is. Commented Dec 28, 2013 at 17:15
  • 1
    You are lucky and not a danger seeker using an account with admin-rights, so you may not write to the root of your machine C-drive. Use a different path to the file you want to create. Try .\\out.txt for example. Commented Dec 28, 2013 at 17:22

1 Answer 1

2

I fixed the problem by running Netbeans with administrator privileges. This caused the exe to also be run as administrator so now I can write to c:.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.