|
Hi all
Recently I faced with a problem with handling mixed text/binary data files.
I need to work with files that start with textual description of the contents (pretty similar to *.ini file) followed by binary data.
This is the code that writes the file (under Windows):
fprintf(fid, 'DescriptionOfTheContents');
fprintf(fid, '\n[Data]\n');
fwrite(fid, Data, cc);
To load data from the file text part is loaded first with series of FGETL and then FREAD reads binary part.
And here is the problem.
MatLab's FPRINTF function replaces \n is replaced with 0x0A character (under windows too). Usually it is OK, since FGETL can read the data back.
But in some cases binary data start with 0x0D byte, thus the "[Data]" string is follo0wed by 0x0A and 0x0D bytes.
For reason that is not clear to me FGETL treats the 0x0A+0x0D combination as EndOfLine character reading one extra byte and thus corrupting the binary data.
Is it possible to tell to MatLab's FGETL function to use only one EOL character?
Or is the TEXTSCAN function the only one that allows to set EOL character directly?
Thanks
|