【发布时间】:2013-12-18 09:08:40
【问题描述】:
我有一个问题,当用户输入相同的 id 时,他们需要再次输入 name 和 id。 当用户输入相同的身份证号码时,我如何只要求用户输入身份证而不是姓名和身份证。请给我一些提示如何做到这一点。谢谢您的帮助!
struct student
{
char student_name[30];
char student_id[10];
int student_course_num[20];
int student_course[10];
};
int main()
{
int student_num;
printf("Enter the number of students:");
scanf("%d",&student_num);
fflush(stdin);
struct student S[student_num];
char TestForId[student_num][10];
int i,j,student_code=1;
for(i=0;i<student_num;i++)
{
printf("Enter the name of student:");
fgets(S[i].student_name,30,stdin);
printf("Enter the Student ID (8 digits):");
fgets(S[i].student_id,10,stdin);
strcpy(TestForId[i],S[i].student_id);
for(j=0;j<i;j++)
{
if(strcmp(TestForId[j],S[i].student_id)==0)
{
printf("The student id has already exit\n");
}
}
student_code++;
}
【问题讨论】:
-
技术上,
fflush(stdin);是未定义的。使用你的程序就不需要了。 -
至于您的问题,您是否尝试过围绕 id 和 check 的输入循环?
-
为什么student_id是int数组?
-
为什么是
student_id[30]?一个学生可以拥有多少个 ID?