Em mới bắt đầu học C và bị kẹt ở phần struct, em lấy code từ tài liệu lập trình C trên này, nhưng khi chạy thì lại bị lỗi:
#include<stdio.h>
void taoToadodiem(int *diembatky);
typedef struct Toadodiem
{
int x;
int y;
} Toadodiem;
int main()
{
Toadodiem diembatky;
taoToadodiem(&diembatky);
printf("%d %d ", diembatky.x, diembatky.y);
return 0;
}
void taoToadodiem(int *diembatky)
{
(*diembatky).x = 0;
(*diembatky).y = 0;
}
Chương trình báo lỗi:
: In function ‘main’:
warning: passing argument 1 of ‘taoToadodiem’ from incompatible pointer type [enabled by default]
note: expected ‘int *’ but argument is of type ‘struct Toadodiem *’
In function ‘taoToadodiem’:
error: request for member ‘x’ in something not a structure or union
error: request for member ‘y’ in something not a structure or union
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 1 warning(s) (0 minute(s), 0 second(s))
Cho em hỏi tại sao lại có lỗi đó và chữa ntn ạ?
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?