구조체를 편집하는 함수에 내 구조체에 대한 포인터를 전달하려고합니다.Typedef 구조체 포인터
이 작동하지 않습니다
typedef struct{
unsigned char x;
unsigned char y;
float z;
}C_TypeDef;
C_TypeDef *ptr_struct; //This is the part that I change to get it to work.
void print_TypeDef(C_TypeDef *report, unsigned char x_data)
{
report->x = x_data;
printf("x is equal to %d", report->x);
}
int main(void)
{
print_TypeDef(ptr_struct,0x23);
getchar();
}
을 지금 내가이 포인터가 여전히 작동하지 않습니다되어 선언 부분을 변경하는 경우. 작동하지 않음 :
C_TypeDef x_struct;
C_TypeDef *ptr_struct;
ptr_struct = &x_struct;
그러나이 코드를 변경하면 작동합니다!
C_TypeDef x_struct;
C_TypeDef *ptr_struct = &x_struct;
제 질문은 왜 처음 두 가지가 작동하지 않는 이유입니까? 이것은 나를 괴롭 히고있다.