Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with segmentation fault in function
    primarykey
    data
    text
    <p>I've been trying to solve this bsearch homework problem for awhile now. I try using my code to first search for one entry like so:</p> <pre><code>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)); } char *SearchList(char *key, char *list[], size_t num) { char **value = bsearch(&amp;key, list, num, sizeof(list[0]), Compare); return (value == 0 ? 0 : *value); } /*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 = SearchList((char *)registrants[0], (char **)attendees, attendeeCount); } </code></pre> <p>My missedFirstMeeting seems to work in calling out a single value properly, but when I try to repeatedly call my SearchList function in a loop like so:</p> <pre><code>for (int i = 0; i &lt; attendeeCount; i++) { *missedFirstMeeting = SearchList((char *)registrants[i], (char **)attendees, attendeeCount); } </code></pre> <p>I get a segmentation fault error. To me it seems like I am doing the same thing, but just repeatedly calling the SearchList(), but obviously something is wrong that I do not see since I get that segmentation fault error. Any ideas? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload