select sort 알고리즘을 짜는데 잘 못 된 것좀 알려주세요~ ^^
갤2
너무 c를 오랜만에 짜서 그런지 ~ 하나도 모르겠네요~
입력을 처음에 받을때 입력을 한줄에 받아야 되는데~ 왜 3개를 받고 엔터 쳐도 안넘어가고
하나더 치고 엔터를 눌러야 넘어갑니다.
실행하다가 정렬하는 부분에서 멈춰 버립니다.
이것 저것 찾아보면서 공부하고 있는데 갑갑하네요~ 답변 부탁드리겠습니다.#include stdio.h
#include string.h
#include stdlib.h
struct Student
{
int hakbun;
char name[20];
int score;
};
void input(struct Student *stu,int count);
void Select_Sort(struct Student *stu,int count);
void output(struct Student *stu,int count);
int main(void)
{
int count;
struct Student *stu;
printf(학생수를 입력하세요:);
scanf(%d,&count);
stu = (struct Student*)malloc(sizeof(stu) * count);
input(stu,count);
output(stu,count);
Select_Sort(stu,count);
output(stu,count);
return 0;
}
void input(struct Student *stu,int count)
{
int i;
for(i=0 ; icount ; i++)
{
printf(%d) 학번 이름 점수 입력:, i+1);
scanf(%d, &stu[i].hakbun);
gets(stu[i].name);
scanf(%d, &stu[i].score);
}
}
void Select_Sort(struct Student *stu,int count)
{
int i,j,temp=0,number=0,index=0;
for(i=0; i (count-1) ; count--)
{
for(j=0; jcount; j++)
{
if(stu[j].scorenumber)
{
count=stu[j].score;
index=j;
}
}
temp = stu[index].score;
stu[index].score = stu[count-1].score;
stu[count-1].score = stu[index].score;
index=0;
}
}
void output(struct Student *stu,int count)
{
int i;
printf(\n\n=== 정렬 결과\n);
printf(%4s %-10s %5s \n,
학번, 이름, 점수);
for(i=0; icount; i++)
{
printf(%4d %-10s %5d\n,
(stu+i)-hakbun,(stu+i)-name,(stu+i)-score);
}
}
-
연분홍 2023-10-03
아~~ 감사합니다^^
scanf 로 받으니까 되네요~ ^^ gets 함수 공부해야 겠네요~ ^^
이제 정렬이 문제네요~ T.T -
장미빛볼살 2023-10-03
쫌만더 자세히 설명좀 해주세요...