c poinetrs ansi c balaguruswami unsolved

problem: a function sort is to be written which sorts a given array in alphabetical order. this sort function receives pointers to two other function strcmp and swap.sort should call these functions via pointers.
till now i have written the following code and its showing me 4 errors.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void swap(char *a,char *b);
char *sort(char *str,void *(stringcmp)(),void *(swp)());
void main()
{
clrscr();
int a;
char *array[5],*dmy[5];
for(a=0;a<5;a++) scanf("%s",array[a]);
dmy[0]=array[0];
sort(array[0],strcmp,swap);
getch();
}
void swap(char *a,char *b)
{
char *dmy;
dmy=a;
a=b;
b=dmy;
return;
}
char *sort(char *str, void *(cmp)(), void *(h)())
{

}
i am new to pointers and i know i am making some huge mistakes. i need help in understanding pointers to functions.
Last edited on
If you are going to sort an array of character arrays then you should define your array another way than you did define it.

Also you did not correctly define pointers to functions

void swap(char *a,char *b);
char *sort(char *str,void *(stringcopy)(),void *(swp)());

For example this

void *(swp)())

means a function that has no parameters and return pointer to void. You shall write the parameter either as

void swp( char *, char * )

or

void ( *swp )( char *, char * )
Topic archived. No new replies allowed.