Here is a part of code I am writing.I am getting a segfault in the CmpFunc function.
The segfault occurs when I compare *a and *b i.e in the "if(*a>*b)" line. I am new to function pointers. So, I might be making a mistake somewhere which I don't realize.I would be very much grateful if anyone points out the mistake.

#include "functions.h"

void stooge_sort(void* A[], int left, int right){
printf("\n DEBUG\n");
int CmpFunc(const void* _a, const void* _b);

int k=CmpFunc(A[left], A[right]);

    	void* temp = A[right];
	A[right] = A[left];
	A[left] = temp;


	 int t = (right-left + 1)/3;


int CmpFunc(const void* _a, const void* _b)
const float* a = (const float*) _a;
const float* b = (const float*) _b;
printf("\n DEBUG\n");
if(*a > *b) return 1;
	if(*a == *b) return 0;
	else         return -1;


OK.. I got my mistake :) I hadn't passed Aand A as pointers(Line 10).
Correct way should have been:

int k=CmpFunc(&A[left], &A[right]);


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.