17070047 / 17070047/CodeStructureCourse

王锡科

Open
#73 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16
Forks
2
PR merge metrics
No merged PRs in 30d

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

Contributor guide

No contributing guide indexed for this repository

Research direction

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.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.