17070047 / 17070047/CodeStructureCourse

赵玉洁

Open
#64 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

# Code
```C
#include
#include
#define MAXSIZE 100
typedef struct
{
int no;//序号
long key;//卡号
char xi[50];//系号
char name[50];//名字
int classes;//班级
}recordtype;
typedef struct
{
recordtype r[MAXSIZE];
int length;
}table;

void QuickSort(table *tab,int left,int right)
{
int i,j;
if(leftr[0]=tab->r[i];
do
{
while(ir[j].key>tab->r[0].key) j--;
if(ir[i]=tab->r[j];
i++;
}
while(ir[i].keyr[0].key) i++;
if(ir[j]=tab->r[i];
j--;
}
}
while(i!=j);
tab->r[i]=tab->r[0];
QuickSort(tab,left,i-1);
QuickSort(tab,i+1,right);
}
}

void creat(table *g)
{
int i,j=1;
printf("输入i,不等于一千可以持续输入\n");
scanf("%d",&i);
g->length=0;
while(i!=1000)
{
g->r[j].no = j;
printf("输入卡号\n");
scanf("%ld",&g->r[j].key);
printf("输入姓名\n");
scanf("%s",&g->r[j].name);
printf("输入系别\n");
scanf("%s",&g->r[j].xi);
printf("输入班级\n");
scanf("%d",&g->r[j].classes);
g->length++;
j++;
printf("输入i,不等于一千可以持续输入\n");
scanf("%d",&i);
}
}
void search(table *l)
{
int k,i;
k=l->length;
char finding[8];
printf("输入要检索的系别;\n");
scanf("%s",&finding);
for(i=1;i<=k;i++)
{
if(strcmp(l->r[i].xi,finding)==0)
{
printf("%d\n",l->r[i].key);
}
}
}
void main()
{
table tab;
int i;
creat(&tab);
QuickSort(&tab,1,tab.length);
printf("学号 姓名 系别 班级 \n");
for(i=1;i<=tab.length;i++)
{
printf("%ld %s %s %d\n",tab.r[i].key,tab.r[i].name,tab.r[i].xi,tab.r[i].classes);
}
search(&tab);
}

```

# Result

![default](https://user-images.githubusercontent.com/45332057/49649393-ff7eb380-fa63-11e8-99bc-5dfc353b57a4.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue shows a C program for sorting and searching student records. The code includes a QuickSort implementation and a search function. Start by examining the main function in the provided code to understand the data flow. Look for potential bugs in the sorting logic or input handling, and run the program to reproduce the issue shown in the image. Check for memory issues, off-by-one errors in array indexing (since it uses 1-based indexing), and ensure string comparisons work correctly.

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.