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
#include
#define MAXSIZE 100
typedef struct
{
int xuehao;
char name[20];
char xibie[20];
int banhao;
}node;
typedef struct
{
node a[MAXSIZE+1];
int len;
}table;
void init(table *s)
{
s->len=0;
}
void creat(table *s,char *filename)
{
int i,d;
FILE *fp;
fp=fopen(filename,"r");
if(fp)
{
fscanf(fp,"%d",&s->len);
for(i=1;i<=s->len;i++)
{
fscanf(fp,"%s%d%s%d",&s->a[i].xibie,&s->a[i].xuehao,&s->a[i].name,&s->a[i].banhao);
}
fclose(fp);
}
else
s->len=0;
}
void display(table *s)
{
int i;
printf("系别 学号 姓名 班号\n");
for(i=1;i<=s->len;i++)
{
printf("%s %d %s %d\n",s->a[i].xibie,s->a[i].xuehao,s->a[i].name,s->a[i].banhao);
}
}
table *quicksort(table *s,int left,int right)
{
int i,j;
if(lefta[0]=s->a[i];
do
{
while((s->a[j].xuehao>s->a[0].xuehao)&&ia[i]=s->a[j];
i++;
}
while((s->a[i].xuehaoa[0].xuehao)&&ia[j]=s->a[i];
j--;
}
}while(i!=j);
s->a[i]=s->a[0];
quicksort(s,left,i-1);
quicksort(s,i+1,right);
}
return s;
}
void erfen(table *s,char xibiek[20])
{
int low=1,high=s->len,mid;
while(low<=high)
{
mid=(low+high)/2;
if(strcmp(s->a[mid].xibie,xibiek)==0)
printf("%s %d %s %d\n",s->a[mid].xibie,s->a[mid].xuehao,s->a[mid].name,s->a[mid].banhao);
if(strcmp(s->a[mid].xibie,xibiek)==1)
high=mid-1;
else
low=mid+1;
}
}
void jiansuo(table *s,char xibiek[20])
{
int i;
printf("系别 学号 姓名 班号\n");
for(i=1;i<=s->len;i++)
{
if(strcmp(s->a[i].xibie,xibiek)==0)
printf("%s %d %s %d\n",s->a[i].xibie,s->a[i].xuehao,s->a[i].name,s->a[i].banhao);
}
}
int main()
{
table *s;
char a[20],filename[20];
int i=0;
s=(table *)malloc(sizeof(table));
init(s);
printf("输入存放信息的文件名 ");
gets(filename);
creat(s,filename);
printf("输出创建的学生借书证信息:\n");
display(s);
quicksort(s,1,s->len);
printf("输出排序后的借书证信息:\n");
display(s);
printf("请输入检索的系别名: ");
scanf("%s",&a);
erfen(s,a);
printf("请输入检索的系别名2: ");
scanf("%s",&a);
jiansuo(s,a);
return 0;
}
```


Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
The issue contains a C program for managing student library cards with sorting and search functions. The problem is not described; the user posted code and screenshots. To understand the issue, examine the code for logical errors, such as the binary search (erfen) that prints matches but may have incorrect comparison logic (strcmp returns 1 for greater, not >0). Review the quicksort implementation for potential bugs. Run the program with sample data to see if it behaves as expected.
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
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100