เมื่อฉันคอมไพล์โค้ดด้วย GCC แล้วรันมัน เมื่อฉันเรียกใช้ฟังก์ชันของฉันในโค้ด มันจะพิมพ์ออกมา: "Segmentation Fault (core dumped)"
ฉันลองค้นหาวิธีแก้ไขใน Google
นี่คือรหัสปัจจุบันของฉัน:
char ** saveLevelPositions() {
int x, y;
char ** positions;
positions = malloc(sizeof(char *) * 25);
for (y = 0; y < 25; y++) {
positions[y] = malloc(sizeof(char) * 100);
for (x = 0; x < 100; x++) {
positions[x][y] = mvinch(y, x);
}
}
return positions;
}
ฉันคาดว่าฟังก์ชันจะทำงานได้อย่างถูกต้องและทำให้เกิดข้อผิดพลาดในการแบ่งส่วน
แก้ไข: สำหรับบริบทเล็กน้อย นี่คือลิงก์ไปยังโครงการ GitHub: https://github.com/xslendix/rogue
mvinch
)? - person Eugene Sh.   schedule 05.04.2019Room ** rooms; rooms = malloc(sizeof(Room) * 2);
- นี่ผิดอย่างแน่นอน เหตุใดrooms
จึงเป็นตัวชี้คู่ ฉันไม่ได้ดูเพิ่มเติม แต่ฉันคิดว่าอาจมีปัญหาอื่น ๆ - person Eugene Sh.   schedule 05.04.2019