Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct clients {
- int id;
- char name[27];
- };
- int comparator(const void* p, const void* q){
- return strcmp(((struct list_node*)p)->name,
- ((struct list_node*)q)->name);
- }
- void sort_by_name(struct list_node *node){
- const int length = count_list(node);
- struct list_node *arr[length];
- int i=0;
- while (node)
- {
- arr[i]=node;
- node = node->next;
- i++;
- }
- printf("Before sort:n");
- for (i = 0; i < length; i++) {
- printf("Id = %d, Name = %sn",
- arr[i]->id, arr[i]->name);
- }
- qsort(arr, length, sizeof(struct list_node), comparator);
- printf("After sort:n");
- for (i = 0; i < length; i++) {
- printf("Id = %d, Name = %sn",
- arr[i]->id, arr[i]->name);
- }
- }
- Before sort:
- Id = 11, Name = adam
- Id = 20, Name = mati
- Id = 25, Name = zenek
- Id = 28, Name = mat
- Process finished with exit code -1073741819 (0xC0000005).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement