yapıya atanırken, Linux ortamında ansi C'de programlama yapıyorum, gcc derleyici kullanıyorum. Aşağıdaki koduC programlama, segmentasyon hatası, tamsayıda
#define USER_IN_LEN 15
#define EXTRA_SPACES 2
#define DELIMS " ,\n"
//define the sruct
typedef struct position
{
int x;
int y;
} Position;
char choice[USER_IN_LEN + EXTRA_SPACES];
//define pointers for strtok and strtol
char *tok;
char *end;
//create pointer o type Position
Position *position;
//get user input with fgets
fgets(choice, USER_IN_LEN, stdin);
//tokenize
tok = strtok(choice, DELIMS);
tok = strtok(NULL, DELIMS);
position->x = (int)strtol(tok, &end, 0); //error, segmentation fault
tok = strtok(NULL, DELIMS);
position->y = (int)strtol(tok, &end, 0);//error, segmentation fault
Temelde programı bazı değerler için kullanıcı girişi alır ve pozisyon yapı içinde saklamak, çevrimiçi biraz araştırma yaptım ve bu position->y = int
kullanabilirsiniz öğrendim, ama neden değil var strtol
ile çalışıyor mu? Hata ayıklayıcısını çalıştırdım ve
'pozisyonu * position' bir başlatılmamış göstericidir. Bunu yapmak için, bir yerde geçerli, muhtemelen 'malloc' hafızasıyla işaret etmelisiniz. –