2
사용 된 포인터/배열 표기법에 문제가 있습니다. 나는 두 개의 목록을 가지고 있고 그것들을 정렬하고 표시하려고 시도한다. 선언문의 의미와 이유에 대해서는 아래 코드에서 3 가지 설명을 들었습니다. 같은 내 코드는 모양이 숙제로 나타납니다, 그래서하는 방식으로 답변 해 드리겠습니다qsort, bsearch를 사용하는 C의 포인터 도움말
int Compare(const void *a, const void *b);
void SortStudents(char *studentList[], size_t studentCount)
{
qsort(studentList, studentCount, sizeof(studentList[0]), Compare);
}
int Compare(const void *a, const void *b)
{
return (strcmp(*(char **)a, *(char **)b));
}
/*Determines which registrants did not attend the first meeting by searching for registrants
that are not in attendees set. */
void DisplayClassStatus(
const char *registrants[], size_t registrantCount,
const char *attendees[], size_t attendeeCount)
{
char **missedFirstMeeting; // not sure if this is the right declaration
char *start, *end;
// not sure if this is right with the &attendees and registrants for the bsearch()
missedFirstMeeting = bsearch(&attendees, registrants, attendeeCount,
sizeof(attendees[0]), Compare);
printf("Missed First Meeting: \n");
//not sure if this the way to traverse through the array using pointers to display
for (start = missedFirstMeeting, end = &missedFirstMeeting[registrantCount-1]; start < end; ++start) {
printf("%s", *start);
}
}
숙제 인 경우 '숙제'태그를 추가하십시오. –