WORD *data = new WORD[amount];
for(i=0;i<Header.iIndices;i++)
{
fscanf(file, "%u", &data);
}
delete[] data;
delete[] word array = error
Hi,
I tried the search but that gave a odbc error so i'm sorry to post such a noob question :$.
At the delete[] data; I get the next error:
Debug Error!
DAMAGE: after Normal block(#76 at 0x(bignumber)
Can somebody tell me what i'm doing wrong ? If i replace the WORD with a int and the fscanf %u with %i everything works fine.
My best guess is that you are writing out of bounds. Are you sure 'Header.iIndices' is smaller or equal to 'amount'
A word is 2 bytes, and an unsigned integer is 4 bytes (in this case), so fscanf writes 2 bytes past the end of the array.
Quote:Original post by smart_idiot
A word is 2 bytes, and an unsigned integer is 4 bytes (in this case), so fscanf writes 2 bytes past the end of the array.
I knew that a word is 2 bytes and a int 4 but why does fscanf write 2 bytes past the end of the array ?
Yes both values are the same. I get the same error when i hardcode the values.
Because %u is an unsigned integer, it's an array of words, and an integer is 2 bytes longer than a word. As hh10k pointed out, use the h modifier.
Ok i replaced the u with a hu and now i get no error's. But however the other problem now is that the data in my array makes totally no sense :s. Instead of 0 2 it's now 5232 or something like that.
Is that because i use a text file instead of a binary file ? If i read the data as a %i i get the correct data. Can somebody please give me a push into the right direction ?
ps. strange i looked in my book and in the msdn help file but i couldn't find a h for fscanf.
[Edited by - twan on October 23, 2004 10:14:41 AM]
Is that because i use a text file instead of a binary file ? If i read the data as a %i i get the correct data. Can somebody please give me a push into the right direction ?
ps. strange i looked in my book and in the msdn help file but i couldn't find a h for fscanf.
[Edited by - twan on October 23, 2004 10:14:41 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement