Skip to main content
4 votes
2 answers
176 views

How is a qsort allocation failure handled?

My question is what happens when qsort in C can not allocate the space it needs to do its thing. The C standard presents qsort as nonerring, but in reality it must need to allocate space for any ...
Kyle's user avatar
  • 1,116
6 votes
1 answer
76 views

For qsort in C, is there a way to specify the sorting index for the comparator function when sorting a multi-dimensional array? [duplicate]

I have the following code : #include<stdio.h> #include<stdlib.h> int comp(const void *a, const void *b) { return (((int*)a)[0] - ((int*)b)[0]); } int main() { int arr[][4] = { ...
Bittu970's user avatar
  • 107
31 votes
5 answers
4k views

Is it OK to use longjmp to break out of qsort?

In In the middle of qsort, is there a way to stop it? some comments mentioned using setjmp/longjmp to break out of a call to qsort() from the comparison function. The language specification doesn't ...
Barmar's user avatar
  • 788k
2 votes
0 answers
134 views

How to construct an array to make qsort() having n^2 time complexity?

I heard a long time ago that the implementation of the qsort function is the quick sorting algorithm and has a worst-case time complexity of n^2. But recently when I was trying to construct a set of ...
Sihan Lv's user avatar
-1 votes
2 answers
90 views

char *array[200] sorting program doesn't read words

The program is expected to sort and display a list of words from a array whose elements are pointers to char. I use malloc to alocate space to each element and use a read_line function to store in the ...
Pepe Cuesta's user avatar
2 votes
2 answers
136 views

Can we sort a structure of arrays using qsort() in C?

My current project requires a turbulence code that will use the velocity components of a fluid to advect a distribution of passive tracers. I have written a code below that uses a structure of arrays (...
ashwin's user avatar
  • 31
1 vote
1 answer
79 views

Can't build huffman tree in C, qsort fails

I try to implement huffman code in C. I have two arrays, one storing all the nodes and one that contains pointers to certain nodes. The second one contains the unfinished trees that I want to combine. ...
TheGlibber's user avatar
1 vote
2 answers
58 views

Questions about character array pointers and secondary pointers and the cmp function in the qsort function [duplicate]

//Sort character array lexicographically (main code): char* words[MAX_SIZE]; qsort(words, len, sizeof(char*), cmp); int cmp(const void* w1, const void* w2) { char** str1 = w1; char** str2 = w2;...
Borges's user avatar
  • 31
1 vote
0 answers
351 views

How can i use the qsort_s function in my c program?

I found qsort_s function in C Refenence, which can provide a another parameter, which offers context information, to the compare function that compared to the qsort function. However, the signature of ...
ISDHN's user avatar
  • 11
0 votes
1 answer
76 views

How do I alphabetically sort multiple 'people' strings without them moving to different 'seats'?

I am writing a seating reservation program in C that involves an option wherein the occupants that are assigned to their seats can be sorted alphabetically. When I choose the option to sort them, the ...
stephanp's user avatar
1 vote
3 answers
137 views

How do I fix my qsort() algorithm? It gives different results every time

I'm currently attempting to create a minimal "3D" engine that renders voxels and planes, but I'm having a bit of a hiccup. Right now, I'm trying to make an algorithm that sorts objects based ...
Keagan Peterson's user avatar
1 vote
3 answers
95 views

qsort in struct, but the sorted struct is messy

I want to sort an array of struct using qsort by their name, But the output is not what I expected. typedef struct node{ char name[64]; char ingredient[10][64]; }node; int compare(const void *...
ident's user avatar
  • 68
1 vote
1 answer
348 views

How to solve the problem incompatible pointer types passing 'char (*)[64]' to parameter of type 'const char **'

I kept getting incompatible pointer types passing 'char (*)[64]' to parameter of type 'const char **' when I pass the name[100][64] in the sort function and end up getting segmentation fault 11 #...
ident's user avatar
  • 68
1 vote
3 answers
113 views

What's wrong with qsort comparator?

So I've been doing my homework on C, and there was this task: "An array of ints is given, write a function that sorts them in following way: first, the even numbers in non-decreasing order, ...
nikita's user avatar
  • 13
0 votes
1 answer
201 views

Sorting struct arrays in C++ with qsort

I would like to use qsort() to sort an array of the student struct. First have it sort by grade, and then try it again using the student ID. I'm seeing two problems: Although the grades are sorted ...
あじうまい's user avatar

15 30 50 per page
1
2 3 4 5
45