Reputation:
void sortRecords(char* records[], int size, int isGreater(const char rec1[],
const char rec2[]));
int isGreaterByName(const char record1[], const char record2[]);
int isGreaterByCity(const char record1[], const char record2[]);
int isGreaterByEmail(const char record1[], const char record2[]);
Actually i dont know how to search that(even know how to call) .. I need to know how to use this type of functions.
I ve these as my function prototypes. i need a example usage for this function :)
I ve tried this
char eMail[30];
sortRecords(addresses,30,isGreaterByName(eMail,eMail));
but compiler gave me
In function 'main':|
|69|error: passing argument 3 of 'sortRecords' makes pointer from integer without a cast|
|50|note: expected 'int (*)(const char *, const char *)' but argument is of type 'int'|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===|
sorry for my bad english ^.^
Upvotes: 1
Views: 79
Reputation: 753725
When you pass a function pointer, you omit the parentheses and arguments:
sortRecords(addresses, 30, isGreaterByName);
When you include the parentheses and arguments, the compiler calls the function and passes the return value (which is usually not a pointer to function) to the function that requires a pointer to function, leading to the problem shown.
You're using a modern version of GCC, which does its best to tell you what's wrong:
expected 'int (*)(const char *, const char *)' but argument is of type 'int'
The return value from the function is an int
; the type expected is int (*)(const char *, const char *)
which is how you write a cast to a function pointer. Ultimately, you need to learn that notation.
Upvotes: 2