The output is this:
tigre@enigma collector $ gcc pro.c tigre@enigma collector $ ./a.out 5 0 0 0 5 0 0 0 5
tigre@enigma collector $ gcc pro2.c tigre@enigma collector $ ./a.out 5 fffffffa ffffffff ffffffbf 5 0 0 0 5 5 fffffffa ffffffff ffffffbf 5 0 0 0 5
Can someone explain it to me?
Thanks
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char ctype; int itype; int itype2; } t_st; int main() { int a; char buffer[9]; t_st mystruct; mystruct.ctype = 5; mystruct.itype = 5; mystruct.itype2 = 5; bzero(buffer, 9); memcpy(buffer, (char*)&mystruct, 9); for(a=0; a<9; a++) printf("%x ", buffer[a]); printf("\n"); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char ctype; int itype; int itype2; } t_st; int main() { int a; char buffer[9]; char *buffer2; t_st mystruct; mystruct.ctype = 5; mystruct.itype = 5; mystruct.itype2 = 5; bzero(buffer, 9); memcpy(buffer, (char*)&mystruct, 9); for(a=0; a<9; a++) printf("%x ", buffer[a]); printf("\n"); buffer2 = (char*)malloc(sizeof(char)*9); bzero(buffer2, 9); memcpy(buffer2, (char*)&mystruct, 9); for(a=0; a<9; a++) printf("%x ", buffer2[a]); printf("\n"); return 0; }