У меня возникают проблемы при использовании strcpy для копирования массива строк внутри двойного указателя с выделенной памятью, но я не могу понять, почему я получаю ошибку сегментации, даже если я ранее выделил память. Вот код:
#include <stdio.h>
#include <string.h>
typedef struct Students {
int q_exams;
char **done_exams;
}Students;
int main() {
Students a;
int i;
char support[30];
printf("how many exams have you done ?\n");
scanf("%d",&(a.q_exams));
a.done_exams=malloc(sizeof(char*)*a.q_exams);
if(a.done_exams==NULL)
{
printf("out of memory\n");
return 0;
}
for(i=0;i<a.q_exams;i++)
{
printf("Insert the name of the exam\n");
scanf("%28s",support);
a.done_exams[i]=malloc(strlen(support)+1);
if(a.done_exams[i]==NULL)
{
printf("out of memory\n");
return 0;
}
strcpy(a.done_exams[i][0],support);
fflush(stdin);
}
return 0;
}
scanf("%48s",support);
char support[30]
? - person Iharob Al Asimi   schedule 01.01.2015