C program output

why i am getting error for this question…please tell me

    #include <stdio.h>
    #include <stdlib.h>
    int values[] = { 88, 56, 100, 2, 25 };
    #define c2(a,b) a>b?a:b
    int main()
    {
       int n;
       qsort(values, 5,sizeof(int),c2);
       printf("\nAfter sorting the list is: \n");
       for( n = 0 ; n < 5; n++ ) {
          printf("%d ", values[n]);
    }
      return(0);
    }

define is macro here.

This is the correct


[1] . You were lacking the compare function which is used with qsort and # signs which are required for preprocessing stage for the compiler before he header file and macro.


  [1]: http://ideone.com/URhvc2

@damn_me actually i want to write cmp function into macro… if not possible then can i write cmp function inside qsort function itself…?

I don’t think so because of macro. Macros are resolved at the preprocessing stage of the compiler i.e. if you have written #define a 4, then wherever in your code a exists, it’ll be replaced by 4. Here in your code what will happen is this : qsort(values, 5,sizeof(int),c2) i.e. c2 will be replaced by the a>b?a:b which will be a compilation error and also your macro is defined with arguments and you are just using c2 in code which is syntactically incorrect. Moreover qsort() calls the comparator function and this is the standard way it is defined. So, I don’t think we can modify anything such!!