17070047 / 17070047/CodeStructureCourse
王锡科
- Langage dominant
- C++
- Étoiles
- 16
- Forks
- 2
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
```c
#include
#include
#define N 50
#define M 200
typedef struct node {
int id; //卡号
char name[N]; //姓名
int classid; //班号
char major[N]; //系别
} st_info;
typedef struct {
st_info adjlist[M];
int s; //学生人数
}student;
void creat(student *A,char file[]) //从文件录入每个学生的信息
{
int i,j,k;
FILE *fp;
fp=fopen(file,"r");
if (fp==NULL)
{
printf("打开文件失败!");
exit;
}
fscanf(fp,"%d",&A->s); //得到学生人数
for (i=0;is;i++)
{
fscanf(fp,"%d",&A->adjlist[i].id); //卡号
fscanf(fp,"%ls",&A->adjlist[i].name); //姓名
fscanf(fp,"%d",&A->adjlist[i].classid); //班号
fscanf(fp,"%ls",&A->adjlist[i].major); //系别
}
fclose(fp);
}
void info_sort(student *A) //对卡号进行冒泡排序 卡号按照从小到大顺序排列
{
int i,j;
int n;
st_info p;
n=A->s;
for (i=0;iadjlist[j].id>A->adjlist[j+1].id)
{
p=A->adjlist[j];
A->adjlist[j]=A->adjlist[j+1];
A->adjlist[j+1]=p;
}
}
}
void search(student *A,char major1[N]) //按系名进行检索
{
int i;
for (i=0;is;i++)
{
//for (int j=0;jadjlist[i].major[0]==major1[0])
{
printf("%3d %ls %4d %ls",A->adjlist[i].id,A->adjlist[i].name,A->adjlist[i].classid,A->adjlist[i].major);
printf("\n");
}
}
}
int main ()
{
student S;
char m[N];
char filename[]="student_info.txt";
creat(&S,filename);
printf("卡号 姓名 班号 系别\n");
for (int i=0;i
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
The issue shows a C program that reads student data from a file, sorts by ID, and searches by major. The bug likely involves file reading or string handling, as the code uses fscanf with %ls for strings. Start by examining the file format in student_info.txt and the scanf calls. Run the program to see where it fails, then debug the creat and search functions. Check if the major comparison only looks at the first character.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c
- Domaine
- cli
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 40/100