Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: zorrodog on January 17, 2014, 06:05:45 pm

Title: windows 8 write file and it can read in dos dir but cant pull it out with fgets
Post by: zorrodog on January 17, 2014, 06:05:45 pm
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
Title: Re: windows 8 write file and it can read in dos dir but cant pull it out with fgets
Post by: Jenna on January 17, 2014, 06:10:04 pm
Go to "Project -> Properties -> Build targets" and set the output and executable directories correctly.

Title: Re: windows 8 write file and it can read in dos dir but cant pull it out with fgets
Post by: BlueHazzard on January 17, 2014, 07:05:05 pm
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
Title: Re: windows 8 write file and it can read in dos dir but cant pull it out with fgets
Post by: zorrodog on January 19, 2014, 01:14:24 am
thanks I definitely appreciate it from yall!