Skip to content

Instantly share code, notes, and snippets.

@moonjuice
Last active August 29, 2015 14:22
Show Gist options
  • Save moonjuice/4b6008bc8c908f19ba47 to your computer and use it in GitHub Desktop.
Save moonjuice/4b6008bc8c908f19ba47 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int int_value1,
int_value2;
char char_value1,
char_value2,
char_value3;
/********************************/
struct struct_prr{
char* int_value1; //就直接當作byte陣列處理,也不需要分成兩個指標
char* int_value2;
char* char_value1;
char* char_value2;
char* char_value3;
}power_ptr;
/*********************************/
/**
char item[7];
char* power_ptr2 = &item; // 不用強制轉型
**/
//struct_prr power_ptr[28];
int main(void) {
// your code goes here
int_value1 = 0x1122;
int_value2 = 0x3344;
char_value1 = 0x55;
char_value2 = 0x66;
char_value3 = 0x77;
/**
item[0] = int_value1 / 256;
item[1] = int_value1 % 256;
item[2] = int_value2 / 256;
item[3] = int_value2 % 256;
item[4] = char_value1;
item[5] = char_value2;
item[6] = char_value3;
**/
power_ptr.int_value1 = (char*) &(int_value1 / 256);
power_ptr.int_value2 = (char*) &(int_value2 / 256);
power_ptr.char_value1 = &char_value1;
power_ptr.char_value2 = &char_value2;
power_ptr.char_value3 = &char_value3;
/*
char i;
for(i=0; i<28; i++){
//printf("%X\r\n",power_ptr2[i]);
}
*/
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment