Understanding Qsort in C Language

Asked 1 years ago, Updated 1 years ago, 339 views

I have a question about C language.

In the qsort assignment, I submitted the following code:

printf("a order:");
scanf("%c", & ad);
qsort(sin,9,sizeof(int), ad=='a'?cmp_u:cmp_d);

'a'?cmp_u:cmp_d); I was told to write separately using the if statement, but I got an error...
Could someone tell me how to write it?

 if(ad=='a')
        qsort(sin,9,cmp_u);
    else
        qsort(sin,9,cmp_d);

c

2022-11-07 10:43

1 Answers

qsort(sin,9,sizeof(int), ad=='a'?cmp_u:cmp_d);

If you want to rewrite this ↑ to use cmp_u, for example,

qsort(sin,9,sizeof(int),cmp_u);// Same

except for the last argument

Shouldn't it be?
(According to your description, there are three arguments.)


2022-11-07 16:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.