pninja005 said:
How does one get the correct length of a text file in standard c ?
I know ftell() does not work due to the carriage return-linefeed
translation.
Thanks for any help !
It's not really possible in standard C. The OS is free to store any
amount of extra bytes along with a file for it's internal purposes. And
as you note some characters may get translated by your environment.
Nearly all modern systems provide system calls to accomplish this.
Using them may be the best strategy. If you still want to do it in
standard C, as Richard notes, you need to read in the whole file and
keep count. This count is not likely to correspond exactly with the on
disk size of the file.