I'm not sure what you mean. How am i defining a function within a function? I was trying to follow this example:
Code:
#include <stdio.h>
#include <stdlib.h>
int values[] = { 40, 10, 100, 90, 20, 25 };
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main ()
{
int * pItem;
int n;
qsort (values, 6, sizeof(int), compare);
for (n=0; n<6; n++)
printf ("%d ",values[n]);
return 0;
}
I tryed moving it around like this, but it still gives me errors.:
Code:
qsort (Array1, 24, sizeof(int), compare);
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
When i move :
Code:
qsort (Array1, 24, sizeof(int), compare);
into main like the example, it says that compare is an undeclared identifier.
The example dosn't use a template, so i'm guessing that's why following the example didn't work out. I'm still not sure how to fix the errors.
**EDIT**
I moved:
Code:
int compare (const void * a, const void * b);
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
before the template, and it works. So i guess the question is how to implement it into the template.
PS:
Not from a different language, I'm just new to templates and sorting functions. I'm in two different programing classes, and i'm learining the sorting functions in one and templates in the other. So, i'm a little confused when trying to use both for the first time.