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.
23 messages · Page 1 of 1 (latest)
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.
!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:
is this windows
also, you don't need to bother allocating memory like you did
you can just repeatedly fgetc and fputc
yes
like:c for(;;){ int c=fgetc(f); if(feof(f)){ break; } if(ferror(f)){ //handle an error break; } fputc(c,nf); if(ferror(nf)){ //handle an error } }
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
I would recommend doing something like this instead btw
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
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
why?