#file not fully read with fread()

23 messages · Page 1 of 1 (latest)

gusty wraithBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

barren remnant
#

!debugger

gusty wraithBOT
# barren remnant !debugger

@undone totem
Have you tried stepping through your code line by line in a debugger?

If you don't know how to use a debugger or don't have one set up, we highly recommend taking the time to do so.
Debuggers are immensely helpful tools for figuring out where problems emerge in code and especially when you're first learning it can help you build intuition and understanding for reasoning through code.

Resources:

stoic bone
#

is this windows

#

also, you don't need to bother allocating memory like you did

#

you can just repeatedly fgetc and fputc

#

yes

stoic bone
#

basically, when you use "r" on windows it interprets it as a text file

#

and on windows, text files use a \r\n -> \n conversion while reading

#

return carriage

#

it's there for historical reasons

stoic bone
#

for a simple program like this

#

plus you should also handle errors like fopen returning null

#

yes it should be, and it's a lot simpler to implement

#

mostly because you're not copying the whole file into memory just to pass it back

#

and it doesn't rely on non-standard tricks like what you did at the start to try and guess the file size

gusty wraithBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

fleet mist
#

This already exists!!

#

Stop reinventing the wheel

visual perch