I have used function pointer in this, but not able to understand why it is not working, here is my piece of code. when i run this code i get not output, i was expecting Decending order and Ascending order to be printed when i give -r in command line, and if no command line input is given it should print ascending order.
What has gone wrong in my code ??
#include <stdio.h>
#include <stdlib.h>
void decending_sort() {
printf ("Decending order \n");
}
void ascending_sort() {
printf ("Ascending order \n");
}
int main( int argc, char **argv) {
int i;
void (*sort)();
while (*++argv) {
if ((strcmp ( *argv, "-r" )) == 0)
sort = decending_sort;
}
sort = ascending_sort;
}
sort.