出现的问题是不管怎么输入输出都显示Not found
1.头文件 stdlib.h
string.h
2.num在定义的时候一定要多几位,题目说12位,需要定义为13位。
#include <stdio.h>
#include<string.h>
struct student{
char num[12];
char name[21];
int a;
int b;
int c;
};
int main()
{
int n;
scanf("%d",&n);
struct student stu[n];
int i;
for(i=0;i<n;i++)
{
scanf("%s %s %d %d %d\n",stu[i].num,stu[i].name,&stu[i].a,&stu[i].b,&stu[i].c);
}
char num2[13];
scanf("%s",num2);
int found=0;
for(i=0;i<n;i++)
{
if(strcmp(num2,stu[i].num)==0)
{
printf("%s %s %d %d %d\n",stu[i].num,stu[i].name,stu[i].a,stu[i].b,stu[i].c);
found=1;
break;
}
}
if(found==0)
{
printf("Not Found");
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char id[13];
char name[21];
int a;
int b;
int c;
}Student;
int main()
{
int n,i;
scanf("%d",&n);
Student students[100];
for(i=0;i<n;i++)
{
scanf("%s %s %d %d %d",students[i].id,students[i].name,&students[i].a,&students[i].b,&students[i].c);
}
char num[13];
scanf("%s",num);
int found=0;
for(i=0;i<n;i++)
{
if(strcmp(num,students[i].id)==0)
{
printf("%s %s %d %d %d",students[i].id,students[i].name,students[i].a,students[i].b,students[i].c);
found=1;
break;
}
}
if(!found)
{
printf("Not Found");
}
return 0;
}