필자가 작성해야하는 기능에 문제가 있습니다. 기발하게도, 이것이 어떻게 작동해야하는지는 모르지만, 그것은 호환되지 않는 포인터 타입 에러를 주었고 그것을 고칠 방법이 확실치 않습니다.호환되지 않는 포인터 유형에서 'qsort'인수 4를 전달합니다.
문제는 compare_last 함수를 참조하는 qsort에 있습니다.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_PERSONS 100
//person structure definition goes here
typedef struct{
char last[32];
char first[32];
int year;
}Person;
//function declarations go here
int compare_last(Person * ptr1, Person * ptr2);
void main(void){//main function goes here
char *infilename[20];
char *outfilename[20];
FILE * fptrin;
FILE * fptrout;
int i, j;
Person musicians[MAX_PERSONS];
printf("Enter input file name: ");
scanf("%s", infilename);
printf("Enter output file name: ");
scanf("%s", outfilename);
strcat(*outfilename, ".htm");
fptrin = fopen(*infilename, "r");
fptrout = fopen(*outfilename, "w");
for(i = 0; i < MAX_PERSONS; i++)
{
fscanf(fptrin, "%s %s %i", musicians[i].last, musicians[i].first, &musicians[i].year);
}
qsort(musicians, i, sizeof(musicians[0]), compare_last);
fprintf(fptrout, "<html>\n<body>\n<title>LAB14</title>\n");
for(j = 0; j < i; j++)
{
fprintf(fptrout, "%s %s %i <br>", musicians[j].last, musicians[j].first, musicians[j].year);
}
fprintf(fptrout, "</body>\n</html>\n");
fclose(fptrin);
fclose(fptrout);
}//end main
//function definitions go here
int compare_last(Person * ptr1, Person * ptr2)
{
int result = strcmp(ptr1 -> last, ptr2 -> last);
if(result != 0)
return result;
else
return strcmp(ptr1 -> first, ptr2 -> first);
}
우리는 '우리가 글을 쓸 것'이라고 씁니다 - 이것이 숙제라는 뜻입니까? –