gsl 관련 도움 주십시오.

numanok의 이미지

아직 초보자라;;

gsl 라이브러리 이용해서 코딩을 했는데.

나름대로는 코딩에 문제가 없다고 생각하는데..

안돌아갑니다..ㅜ.ㅜ

도움 좀 주세요''

#include<stdio.h>
#include<gsl/gsl_sort_int.h>
#include<gsl/gsl_heapsort.h>

int input[20],output[20];

 int compare(const int * a, const int * b)
{
    if (*a > *b)
       return 1;
    else if (*a < *b)
       return -1;
    else
       return 0;
}

int main(){
  int i;
  printf("숫자 10개를 입력하시오:");
 for(i=0;i<10;i++){
  scanf("%d",&input[i]);
    }
 
gsl_heapsort(*input,10, sizeof(int),compare);
gsl_sort_int_smallest (output, 5, input, 1, 10);

printf("sort 결과 중 작은 5개:%d %d %d %d %d",output[1],output[2],output[3],output[4],output[5]);
printf("입력 숫자 중 작은 5개:%d %d %d %d %d",gsl_sort_int_smallest());
}

sort시킨것에서 앞에서부터 다섯개 출력하는 것과, 함수이용해서 바로 다섯개 뽑아내는것 두개 출력하는 프로그램입니다..[/code]

File attachments: 
첨부파일 크기
파일 c15597.c664바이트
ssehoony의 이미지

함수 원형이
gsl_heapsort (void * array, size_t count, size_t size, gsl_comparison_fn_t compare)
이거 인데

gsl_heapsort(*input,10, sizeof(int),compare);
이렇게 사용하셨네요?

gsl_heapsort(input,10, sizeof(int),compare);
이렇게 사용하셔야 할 듯 하네요.

좀 더 깔끔하게 하자면
gsl_heapsort((void*)input, sizeof(input)/sizeof(input[0]), sizeof(int), compare);

그리고 compare 함수의 리턴 타입을 int 로 하셨던데 (int 로 해도 잘 작동 할 듯 하지만)
실제로는 gsl_comparison_fn_t 이 되야 할 듯 하군요.

익명 사용자의 이미지

C의 배열인덱스는 0부터 시작합니다.
int a[10];
이라면, 0~9가 적법한 인덱스지요.

그리고, 포인터를 좀더 보셔야겠네요.