17070047 / 17070047/CodeStructureCourse
王锡科
- Linguagem predominante
- C++
- Estrelas
- 16
- Forks
- 2
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
```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
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- c
- Domínio
- cli
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 40/100