17070047 / 17070047/CodeStructureCourse

马智秀

Open
#89 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
#include
#define MAXSIZE 100
typedef struct
{
char cardnmuber[20];//卡号
char name[10];//名字
char academy[120];//系别
char classnumber[20];//班级
}recordtype;//学生借书证信息
typedef struct
{
recordtype r[MAXSIZE+1];
int length;
}table;
void display(table *tab)//输出
{
int i;
printf("卡号 姓名 系别 班级 \n\n");
for(i=1;i<=tab->length;i++)
{
printf("%s",tab->r[i].cardnmuber);
printf("%20s",tab->r[i].name);
printf("%20s",tab->r[i].academy);
printf("%20s",tab->r[i].classnumber);
printf("\n");
}
}
table *quicksort(table *tab,int left,int right)//排序
{
int i,j;
if(leftr[0]=tab->r[i];
do
{
while(strcmp(tab->r[j].cardnmuber,tab->r[0].cardnmuber)>0&&ir[i].cardnmuber,tab->r[j].cardnmuber);
strcpy(tab->r[i].name,tab->r[j].name);
strcpy(tab->r[i].academy,tab->r[j].academy);
strcpy(tab->r[i].classnumber,tab->r[j].classnumber);
i++;
}
while(strcmp(tab->r[i].cardnmuber,tab->r[0].cardnmuber)<0&&ir[j].cardnmuber,tab->r[i].cardnmuber);
strcpy(tab->r[j].name,tab->r[i].name);
strcpy(tab->r[j].academy,tab->r[i].academy);
strcpy(tab->r[j].classnumber,tab->r[i].classnumber);
j--;
}
}while(i!=j);
tab->r[i]=tab->r[0];
quicksort(tab,left,i-1);
quicksort(tab,i+1,right);
}
return tab;
}
void find(table *tab,char academy[])//查找
{
int k=tab->length;
printf("卡号 姓名 系别 班级 \n\n");
while(k>=1)
{
if(strcmp(tab->r[k].academy,academy)==0)
{
printf("%s",tab->r[k].cardnmuber);
printf("%20s",tab->r[k].name);
printf("%20s",tab->r[k].academy);
printf("%20s",tab->r[k].classnumber);
printf("\n");
}
k--;
}
}
int main()
{
table librarycard;
table *librarycard1;
char academy[10];
int n,i;
printf("请输入各个学生的借书信息:\n");//录入各个学生的借书信息
scanf("%d",&n);
while(n!=-1)
{
getchar();
printf("卡号:");gets(librarycard.r[n].cardnmuber);
printf("姓名:");gets(librarycard.r[n].name);
printf("学院:");gets(librarycard.r[n].academy);
printf("班级:");gets(librarycard.r[n].classnumber);
librarycard.length=n;
scanf("%d",&n);
}
printf("请输入需要查找的系别名称:");//查找某个系别的学生借书信息
scanf("%s",academy);
find(&librarycard,academy);
printf("按卡号对学生借书信息进行排序:\n");
librarycard1=quicksort(&librarycard,1,librarycard.length);
display(librarycard1);
return 0;
}
```

![qq 20181208134819](https://user-images.githubusercontent.com/32426394/49682651-bd508300-faf2-11e8-8400-41618fe25534.png)
![qq 20181208134827](https://user-images.githubusercontent.com/32426394/49682652-bd508300-faf2-11e8-9bed-f06583c44d80.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue shows a C program for managing library cards with sorting and search functions. The code likely has bugs in the quicksort implementation or input handling. Start by examining the quicksort function in the provided snippet, focusing on the array indexing and string copying logic. Run the program with sample data to see the output and identify where it fails. Check the main function's input loop for potential issues with array bounds and the sentinel value -1.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.