如果我調試我的代碼,然後我得到「編程接收到的信號SIGSEGV,分段錯誤。」這裏是我的代碼 -編程接收到的信號SIGSEGV,分段故障。當調試
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
struct term
{
char* name;
long int id;
float term_gpa;
};
struct term *term_ptr, student;
term_ptr = &student;
strcpy(term_ptr->name,"niton");
term_ptr->id = 942044;
term_ptr->term_gpa = 3.75;
printf("Name : %s",term_ptr->name);
printf("Name : %s",student.name);
getch();
return 0;
}
我得到這個錯誤第17行。請幫助我!對不起,我的英語不好。
感謝,但如果我改線17像這個 - term_ptr->名稱= 「氡」;那麼不會發生錯誤!再次感謝 – Mominul
如果你這樣做,你只需要將一個字符串文字分配給你的指針。如果你只是想用term_ptr-> name來閱讀,那就沒問題。然而,試着寫一些東西......看看會發生什麼。 – dragosht