Advertisement
| null |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: |
#include <string.h>
typedef struct NetworkFrame_
{
unsigned ack : 1;
unsigned tseq : 7;
} NetworkFrame;
void main(void)
{
NetworkFrame nf;
NetworkFrame * pnf;
char* test;
nf.ack = 1;
nf.tseq = 12345678;
test = (char*)&nf; // Here you can't the address not the object itself!
pnf = (NetworkFrame *) test;
memcpy(&nf, test, sizeof(NetworkFrame));
printf("%x", test);
system("PAUSE");
}
|
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
|
Loading Advertisement... |
| Open Discussion |
| null |
| null |
| null |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
NetworkFrame nf;
int i = 0;
for (i = 0; i < sizeof(NetworkFrame); ++i) {
printf("%02x ", ((unsigned char*) &nf)[i]);
}
/* OR even : */
NetworkFrame nf;
unsigned char *ptr = &nf;
int i = 0;
for (i = 0; i < sizeof(NetworkFrame); ++i, ++ptr) {
printf("%02x ", *ptr);
}
|
| null |
| null |
| null |
| null |
| null |
| null |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: |
#include <string.h>
typedef struct NetworkFrame_
{
unsigned ack : 1;
unsigned tseq : 7;
} NetworkFrame;
int main(void)
{
NetworkFrame nf;
NetworkFrame * pnf;
unsigned char* test;
int i = 0;
nf.ack = 1;
nf.tseq = 2;
test = (unsigned char*)&nf;
pnf = (NetworkFrame *) test;
memcpy(&nf, test, sizeof(nf));
for (i = 0; i < sizeof(nf); ++i)
{
printf("%02x ", test[i]);
}
system("PAUSE");
return 0;
}
|
| null |
| null |
| null |
| null |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: |
#include <string.h>
typedef struct NetworkFrame_
{
unsigned ack : 1;
unsigned tseq : 7;
unsigned char payload[3];
} NetworkFrame;
int main(void)
{
NetworkFrame nf;
NetworkFrame *pnf;
unsigned char* test;
int i = 0;
nf.ack = 1;
nf.tseq = 2;
nf.payload[0] = 0;
nf.payload[1] = 0;
nf.payload[2] = 0;
nf.payload[3] = 0;
test = (unsigned char*)&nf;
pnf = (NetworkFrame *) test;
memcpy(&nf, test, sizeof(nf));
for (i = 0; i < sizeof(nf); ++i) {
printf("%04x ", test[i]);
}
system("PAUSE");
return 0;
}
|
| null |
| null |
| null |
| null |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: |
#include <string.h>
#include <stddef.h>
#pragma pack(1)
typedef struct NetworkFrame_
{
unsigned ack : 1;
unsigned tseq : 7;
unsigned char payload[3];
} NetworkFrame;
int main(void)
{
NetworkFrame nf;
NetworkFrame *pnf;
unsigned char* test;
int i = 0;
nf.ack = 1;
nf.tseq = 2;
nf.payload[0] = 0;
nf.payload[1] = 0;
nf.payload[2] = 0;
nf.payload[3] = 0;
test = (unsigned char*)&nf;
pnf = (NetworkFrame *) test;
memcpy(&nf, test, sizeof(nf));
for (i = 0; i < sizeof(nf); ++i) {
printf("%04x ", test[i]);
}
system("PAUSE");
return 0;
}
|
| null |
| null |
| null |
| null |
| null |