这是我的一段代码,我试图让它更简单我试图将一个字符串分配给一个数组内的结构内的指针,我也想初始化指向 NULL 的指针,以便我可以检查是否存在已经是使用房间的医生了...我不断收到段错误错误我将不胜感激任何帮助
struct appointment{
char *SSN;
int status;//is appointment already taken?
};
struct room{
int doctorID;
char *doctorname;
struct appointment hours[10];
};
struct room clinic[5];
for(int i = 0; i < 5; i++){ //I was trying to initialize all pointers to NULL but didn't work
clinic[i].doctorID = 0;
for(int j = 0; i < 10; i++){
clinic[i].hours[j].status = 0;
}
}
for(int i = 0; i < 5; i++){
clinic[i].doctorname = malloc(sizeof(char) * 30); // Am I doing something wrong here?
*clinic[i].doctorname = "fernando";
printf("the name of the doctor on clinic %d is %s\n", i, clinic[i].doctorname
free(consultorios[i].medico);
}
return 0;
}