views:

39

answers:

1

Hello. I'm using CreateFileA and ReadFile in Visual C++ 2008 to open and read an ASCII text file into memory. This works okay (I can view its contents in memory), but with one exception. For some reason the TAB characters (0x09) are being changed to NULLs (0x00). Needless to say, this is wreaking havoc when I try to parse the file. Does anybody know what might be causing this, or how I can fix it?

This is how I'm opening the file:

hHandle = CreateFileA( pPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
GetFileSizeEx( hHandle, &tFileSize );
pBuf = (UINT8 *)malloc( tFileSize.LowPart );
ReadFile( hHandle, pBuf, tFileSize.LowPart, &dwBytesRead, NULL );

My project code has robust error-handling, and I'm not getting any errors. Any suggestions would be appreciated.

Thanks.

+1  A: 

This seems really unlikely. Have you used some other tool to examine the file on-disk, and verify that the tab characters are there?

Mark Bessey
Actually, I think I just found the answer. It appears that strtok_s replaces each token with NULL as it moves through the string.
Jim Fell
Yeah, that'd do it...
Mark Bessey