Это массив указателей на char, но эти указатели не ссылаются на корректную память.
Сначала выделите для них память:
int main(void)
int pos;
char *labels[8];
for (pos=0; pos<8; ++pos) {
labels[pos]=malloc(LABELCAP);
scanf("%17s",labels[pos]);
}
for (pos=0; pos<8; ++pos) {
printf("%s\n",labels[pos]);
free(labels[pos]);
}
return 0;
}
другой вариант
int main(void) {
int pos;
char labels[8][LABELCAP];
for (pos=0; pos<8; ++pos) {
scanf("%17s",labels[pos]);
}
for (pos=0; pos<8; ++pos) {
printf("%s\n",labels[pos]);
}
return 0;
}
Переведено с английского·Показать оригиналThose pointers form an array pointing to char, but they aren't referncing any valid memmory.
First allocate storage for those pointers:
int main(void)
int pos;
char *labels[8];
for (pos=0; pos<8; ++pos) {
labels[pos]=malloc(LABELCAP);
scanf("%17s",labels[pos]);
}
for (pos=0; pos<8; ++pos) {
printf("%s\n",labels[pos]);
free(labels[pos]);
}
return 0;
}
another option is
int main(void) {
int pos;
char labels[8][LABELCAP];
for (pos=0; pos<8; ++pos) {
scanf("%17s",labels[pos]);
}
for (pos=0; pos<8; ++pos) {
printf("%s\n",labels[pos]);
}
return 0;
}