我有我的C語言編寫的程序確實有問題設置一個變量,它停止在該行e->identifiant=0;
C,在結構
代碼:
struct Evenement* e=(struct Evenement*)(malloc(sizeof(struct Evenement)));
e->identifiant=0;
有:
struct Evenement{
int identifiant;
char titre[100];
struct Creneau creneau;
char lieu[50];
char description[500];
};
你有想法嗎?
'malloc'是否成功?您不需要在C程序中投射返回值。 – 2013-05-04 15:28:26
它如何停止?你會得到分段錯誤嗎?如果@CarlNorum可能在正確的軌道上,malloc沒有成功。在嘗試分配給它之前,你應該檢查'e'是否爲非零(非NULL)。 – 2013-05-04 15:29:37
事實上,在malloc之後e是NULL ... 我不明白爲什麼... Malloc寫入正確...不是? – user1360503 2013-05-04 15:31:20