D
dg
helo i need some help with unions
i have a structure that has two int's and one five byte char string
and i need to convert the hole thing into a string
to pass to another pc
but i cnat get it to work
code__
// main prog
#include <stdio.h>
#include <winsock.h>
struct PACKETFRAME
int num1;
int num2;
char junk[5];
};
union MYUNION
{
PACKETFRAME dataframe;
char string[21];
};
union MYUNION2
{
char string[21];
PACKETFRAME dataframe;
};
main(void)
{
PACKETFRAME sizor;
MYUNION thing1;
MYUNION2 thing2;
printf("size of sizor %d \n",sizeof sizor);
printf("size of thing1 %d \n",sizeof thing1);
printf("size of thing2 %d \n",sizeof thing2);
thing1.dataframe.num1 = 10;
thing1.dataframe.num2 = 15;
lstrcpy (thing1.dataframe.junk, "abcd");
printf(" %d %d %s
\n",thing1.dataframe.num1,thing1.dataframe.num2,thing1.dataframe.junk);
printf ("thing1 %s, thing2 %s \n" ,thing1.string,thing2.string);
lstrcpy(thing2.string,thing1.string);
printf ("thing1 %s, thing2 %s \n" ,thing1.string,thing2.string);
printf ("%d %d %s
\n",thing2.dataframe.num1,thing2.dataframe.num2,thing2.dataframe.junk);
}
code__end
i have a structure that has two int's and one five byte char string
and i need to convert the hole thing into a string
to pass to another pc
but i cnat get it to work
code__
// main prog
#include <stdio.h>
#include <winsock.h>
struct PACKETFRAME
int num1;
int num2;
char junk[5];
};
union MYUNION
{
PACKETFRAME dataframe;
char string[21];
};
union MYUNION2
{
char string[21];
PACKETFRAME dataframe;
};
main(void)
{
PACKETFRAME sizor;
MYUNION thing1;
MYUNION2 thing2;
printf("size of sizor %d \n",sizeof sizor);
printf("size of thing1 %d \n",sizeof thing1);
printf("size of thing2 %d \n",sizeof thing2);
thing1.dataframe.num1 = 10;
thing1.dataframe.num2 = 15;
lstrcpy (thing1.dataframe.junk, "abcd");
printf(" %d %d %s
\n",thing1.dataframe.num1,thing1.dataframe.num2,thing1.dataframe.junk);
printf ("thing1 %s, thing2 %s \n" ,thing1.string,thing2.string);
lstrcpy(thing2.string,thing1.string);
printf ("thing1 %s, thing2 %s \n" ,thing1.string,thing2.string);
printf ("%d %d %s
\n",thing2.dataframe.num1,thing2.dataframe.num2,thing2.dataframe.junk);
}
code__end