DZ小明 2016-12-11 15:07 采纳率: 75%
浏览 1037
已采纳

结构体内元素的赋值问题

定义一个结构体:
typedef struct person{
char name[32];
char sex;
int age;
char num[16];
char addr[128];
} people_t, *people_p, **people_pp;

typedef struct tab
{
int size;
int max;
people_p list;
}tab_t, *tab_p, **tab_pp;

然后给people结构体中的元素通过tab中的list赋值。我是下面这么写的,
但是运行不过去,每次都会中断。

  char sex1=0;
        int age1=0;
        fflush(stdin);
        gets(c->list->name);
        fflush(stdin);

        scanf("%c", sex1);
        c->list->sex = sex1;//大概就是这里有错,但是实在想不出来怎么弄了
        fflush(stdin);

        scanf("%d", &age1);
        c->list->age = age1;//再看看这块可以吗?
        fflush(stdin);

        gets(c->list->num);
        fflush(stdin);

        gets(c->list->addr);
        fflush(stdin);
  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-11 15:25
    关注

    scanf("%c", sex1);
    ->
    scanf("%c", &sex1);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?