Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42731

Having trouble switching endians

$
0
0
I am trying to learn some basics in how to read and write lseek functions. I am having an issue with endians. I found a source code that is supposed to work, however it is reading everything backwards for me. This is my code:

Code:

Code:
for(i = 0;i < 7;i++)
                {
                lseek(handle,1200 + i * 60,SEEK_SET);
                read(handle,&(member[i].name),12);
                read(handle,&(member[i].age),2);
.

The only problem is that for the name and some other variables it is reading it as nalyeK instead of Keylan. It is also throwing off some of my numbers. I am trying to get House numbers, and instead 2046 (07FE) it is giving me 65031 (FE07). I know it is an endian issue, as I have had this kind of thing happen in vb. I am not sure how to fix it in C++.

I have found a lot of different things on Google regarding swapping bytes and switching endians, but most of these codes are many lines long (8 for the shortest, and almost 20 for the longer ones). I am not sure how to implement them. If I need to do this every time I need to switch, or if it will permanently switch it in the program.

Does anyone have any ideas? I can provide more of the code if need be.

Viewing all articles
Browse latest Browse all 42731

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>