17070047 / 17070047/CodeStructureCourse

王锡科

未關閉
#73 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C++
星號
16
分支
2
PR 合併指標
30 天內沒有已合併 PR

描述

```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

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

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.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c
領域
cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
40/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。