Click to See Complete Forum and Search --> : File input


Kenshin
October 14th, 2002, 08:18 AM
I need input into the file the string with size less than 64kb. What is the optimized way to do this?
I use _write(...) function, no streams, but with streams is the so problem too. The problem is when I try to write string if file, sometimes programm writes more bytes in file, then in string is. More on 20. I dont imagine where may the error be. In number of written bytes I point strlen(my string). The string is dynamic chars array.

Is anybody saw this problem?
Thanks anymore

cup
October 14th, 2002, 09:05 AM
If you post your code which writes the string to the file, we might be able to see the problem more easily than if you just described it.

JMS
October 14th, 2002, 01:48 PM
The write function is very quick to blast memory to a file. If you're getting extra garbage in the file when you're done you might check two things..

One are you openning the file in a mode which clears the previous contents of the file or are you adding to what's already there?

Two when you specify how many bytes are going into the file are you dumping the size of the memory block? or are you dumping the string length. If you're dumping the memory block... say..

char szBuffer[2048] = "blah blah blah";

and you're saying something like sizeof(szBuffer);......

Now if you want to get rid of that garbage then just use

strlen(szBuffer) instead of sizeof...