


uj5u.com熱心網友回復:
struct studeng stud[n];這兒有問題呢。n是隨機值,不確定大小;C語言不支持不確定的陣列長度;可以考慮用動態申請空間的方式來實作:
struct studeng *stud = NULL;
在scanf后面加上一句申請空間的陳述句:
stud = (struct student *)malloc(sizeof(struct student));
if (!stud)
exit(0);
后面對stud可以以陣列的形式訪問和操作;
最后注意不適用stud時,記得free(stud);釋放;
uj5u.com熱心網友回復:
stud = (struct student *)malloc(sizeof(struct student) * n);
if (!stud)
exit(0);
用這個,上面那個有問題,忘了乘于n了。這個n是輸入之后的n;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284656.html
標籤:C語言
上一篇:matlab問題