#include <stdio.h>

#include <stdlib.h>

#include <string.h>


struct student{

int id;

char name[20];

}Student;


//qsort 비교 함수

int compareStd(const void *a, const void *b) 

    struct student *pa = (struct student *)a; 

    struct student *pb = (struct student *)b; 


    return pa->id - pb->id; 

}


//bsearch 비교 함수

int compareStd2(const void *pKey, const void *pValue){

return (((student *)pKey)->id - ((student *)pValue)->id);


}


void main(){


int i,input;

struct student *std, *ptr;

std = (struct student *)malloc(sizeof(struct student)*10);

// 구조체 배열 초기화

std[0].id = 20084688;

strcpy(std[0].name, "조윤식");


std[1].id = 20072648;

strcpy(std[1].name, "서웅교");


std[2].id = 200914204;

strcpy(std[2].name, "김종근");


std[3].id = 200914545;

strcpy(std[3].name, "유대혁");


std[4].id = 201013372;

strcpy(std[4].name, "홍나연");


std[5].id = 201013192;

strcpy(std[5].name, "강한나");


std[6].id = 20084391;

strcpy(std[6].name, "박대서");


std[7].id = 20070302;

strcpy(std[7].name, "이주혁");


std[8].id = 20078071;

strcpy(std[8].name, "권영우");


std[9].id = 201010712;

strcpy(std[9].name, "허하연");

//배열 출력

for(i=0; i<10; i++){

printf("%d %s\n", std[i].id, std[i].name);

}


puts("----------qsort로 정렬------------");

qsort(std,10,sizeof(struct student), compareStd);

for(i=0; i<10; i++){

printf("%d %s\n", std[i].id, std[i].name);

}


puts("검색할 id를 입력하세요");

scanf("%d", &input);

ptr = (student *)bsearch(&input,std,sizeof(struct student), compareStd2);


if(ptr == NULL)

puts("데이터를 찾지 못했습니다.");

else

printf("%s\n", );


free(std);

}




compareStd2에서 리턴값이 잘못된거같은데... 수정좀 부탁드려요ㅜ