Author Topic: windows 8 write file and it can read in dos dir but cant pull it out with fgets  (Read 3105 times)

Offline zorrodog

  • Single posting newcomer
  • *
  • Posts: 2
I used fprintf to write "good day all" in a file, wrote it and I can go in dos and >type goodday.txt and it will print the message but when I try to read the file with fgets I keep getting kicked out for null at if(fh==NULL) so I know codeblocks is not finding the file pointer. How can you tell where code blocks is looking to read the file at. The file was written from codeblocks? any suggestions

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Go to "Project -> Properties -> Build targets" and set the output and executable directories correctly.


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2430
I used fprintf to write "good day all" in a file, wrote it and I can go in dos and >type goodday.txt and it will print the message but when I try to read the file with fgets I keep getting kicked out for null at if(fh==NULL) so I know codeblocks is not finding the file pointer. How can you tell where code blocks is looking to read the file at. The file was written from codeblocks? any suggestions
only for clarity: C::B doesn't do here anything. Your program does write the file to disk, and you program (or the operating system) is not finding the file. So probably your file path is wrong.
If your path in the code is right, a possible cause (if you are using relative path) could be, that codeblocks tells your program that it should look in the project folder as base path for relative paths. You can tell c::b what base path your program should get. This is done as jens mentioned.
if you run your program from the command prompt it should work if all paths are right.

greetings

Offline zorrodog

  • Single posting newcomer
  • *
  • Posts: 2
thanks I definitely appreciate it from yall!