Pointers 向链表结构添加字符时遇到问题?

Pointers 向链表结构添加字符时遇到问题?,pointers,linked-list,structure,Pointers,Linked List,Structure,我当前在提示为当前程序添加字符时失败。我可以添加一个数字,但它会提示添加一个字符,但会跳到输入部分,直接询问我是否要继续 #include <stdio.h> #include <malloc.h> #include <stdlib.h> main() { struct node { int num; char gender[3]; struct node *ptr; }; t

我当前在提示为当前程序添加字符时失败。我可以添加一个数字,但它会提示添加一个字符,但会跳到输入部分,直接询问我是否要继续

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

main()
{
    struct node
    {
        int num;
        char gender[3];
        struct node *ptr;
    };

    typedef struct node NODE;
    NODE *head, *first, *temp = 0;
    int count = 0;
    int choice = 1;
    first = 0;

    while (choice)
    {
        head  = (NODE *)malloc(sizeof(NODE));
        printf("Enter the Student Identification Number\n");

        scanf("%d", &head-> num);
        printf("Enter the Student gender (M)or(F)\n");
        scanf("%c", &head-> gender);
        if (first != 0)
        {
            temp->ptr = head;
            temp = head;
        }else
        {
            first = temp = head;
        }
        fflush(stdin);
        printf("Would you like to do another entry(Type No(0) or Yes(1))?\n");
        scanf("%d", &choice);
    }
    temp->ptr = 0;
    /*  reset temp to the beginning */
    temp = first;
    printf("\nStudent Information\n");
    while (temp != 0)
    {
        printf("Student ID number: %d\n", temp->num);
        printf("Student gender: %c\n", temp->gender);
        count++;
        temp = temp -> ptr;
    }
    printf("No. of Students inputted into system: %d\n", count);
}
#包括
#包括
#包括
main()
{
结构节点
{
int-num;
性别[3];
结构节点*ptr;
};
typedef结构节点;
节点*head,*first,*temp=0;
整数计数=0;
int-choice=1;
第一个=0;
while(选择)
{
头=(节点*)malloc(节点大小);
printf(“输入学生身份证号码”);
scanf(“%d”,&head->num);
printf(“输入学生性别(M)或(F)\n”);
scanf(“%c”、&head->gender);
如果(第一个!=0)
{
温度->ptr=压头;
温度=水头;
}否则
{
第一个=温度=水头;
}
fflush(stdin);
printf(“您想做另一项输入(键入No(0)或Yes(1))?\n”);
scanf(“%d”,选择(&C);
}
温度->ptr=0;
/*将温度重置到开始位置*/
温度=第一;
printf(“\n学生信息\n”);
while(温度!=0)
{
printf(“学生ID号:%d\n”,临时->数值);
printf(“学生性别:%c\n”,临时->性别);
计数++;
温度=温度->ptr;
}
printf(“输入系统的学生人数:%d\n”,计数);
}

我建议您投入更多精力解释a)您必须完成的任务,b)您期望的行为,c)您观察到的行为。a)我需要创建一个程序,使用链表输入学生ID和性别,然后依次打印ID和性别b)我希望能够在输入性别提示后输入一个字符c)我运行该程序时最终得到的结果是“输入学生性别(M)或(F)\n”紧接着“您想做另一个输入(键入No(0)或Yes(1))?”并且它不允许我为上一个问题输入任何内容