Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am using sprintf for reading bytes from hex file '%02x' is used for reading
/////
C#
for(i=start;i>=end;i--)
    {
        sprintf(hexstr, "%02x",buffer[i]);
         strcat( dataArray,  hexstr);
    }


if i call this function
C++
getByteLittleEndian(offset+4,offset,buffer);

error comes memmory curruption error


if i call
C++
getByteLittleEndian(offset+2,offset,buffer);

no error,it's only working if the difference is 2 otherwise error comes how to solve this
Posted
Updated 4-Apr-14 7:14am
v2
Comments
[no name] 3-Apr-14 2:23am    
This is incomplete and appears to have nothing to do with endian-ness. You are probably accessing beyond memory you own - but how? '%02x' isn't bytes. What's buffer? What's getByteLittleEndian()? Please post your code.
Stefan_Lang 3-Apr-14 3:08am    
Have to agree with pwasser. First off you'll need sscanf, not sprintf, if your purpose is to transform a series of hex bytes into byte values. Second, there's no such thing as "byte-endian": the first hex digit is always the high-nibble.

I strongly suggest you read up on those things before continuing to try your hand at low level programming!
Rage 3-Apr-14 4:59am    
Arf, "I strongly suggest you read up on those things before continuing to try your hand at low level programming!"

I think we need buttons for automatically inserting some text quotes. This would be one of them.
pasztorpisti 4-Apr-14 16:38pm    
Ironically, in my opinion he should know the basics of low level programming also to understand this problem and other "higher level chapters of low level programming" he tries to deal with. One of the biggest general problem these days is that people don't know that memory is just a big byte array and a pointer is an index into it. Understanding this eliminates the fog floating around the pointers of higher level languages and this clear the path to understanding many other things.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900