Byteorder messed up.

I made code which should output the following:
but it outputs this:
If you look wel,
you see that they are the same, but that the byteorder is just messed up
so, generally speaking:
I think it has something to do with most significant byte and ....
Is there a "standart solution" for my problem (like defining "which byteorder" you want or something else....)???

Thanks in advance.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

SteHConnect With a Mentor Commented:
You can treet a long as char[4] and output it byte by byte. That way you should have full control only you need to find out if you cast these types whether bytes are swapped or not.

long lValue;
char pLong[4];
pLong = (char[4]) lValue;

union {
long lValue;
char cValue[4];
griesshConnect With a Mentor Commented:
Without knowing what you do it is hard to tell you how to make it right. Could you post the code taht creates those strings?
teuntjeAuthor Commented:
Could these lines have something to do with the byteorder (orry, I'm new to c / byteorder / programming)
#define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
#define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16)(val))
Otherwise I should adapt these lines: (?):
            unsigned int i;
            for (i = 0; i < 16; i++)
                  printf("%02x", Mtext.buffer[i]);

Thanks again.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

It can well be that the two defines are messing things up. How are they used? The first returns an uint16 out of a char array and the other puts an uint16 into a char array. Depending on endianess this can change things.
teuntjeAuthor Commented:
There used in a function to convert to unicode:
static int _my_mbstowcs(int16* dst, uchar* src, int len)
      int      i;
      int16      val;

      for (i = 0; i < len; i++)
            val = *src;
            SSVAL(dst, 0, val);
            if (val == 0)
      return i;
But I don't see how I should adapt the code so that the ord is correct....
This will, if at all change the two bytes in val. If the characters in the unicode string are readable you don't have a problem there. It is somewhere else. Mostlikely a similar cast but from int32 to char* (here is from (u)int16 to char*. Where does the original string come from?
teuntjeAuthor Commented:
There isn't a cast from int32...

char      text1[129];  
strcpy(text1, "eE&1");

The complete source is long (3 files, total over 500 lines...), but if you think it could help you (so, help me ), you can mail me at plinius at gmail dot com...
teuntjeAuthor Commented:
Solved. I found it. There where different outputfunctiond defined (and I used the wrong one, off course).
Thanks all for your help.
All Courses

From novice to tech pro — start learning today.