B
Bill Cunningham
I have these 3 functions and before I compile I am going to ask about
them. This is for qsort. I tried to tackle this once and couldn't get it I
think I get it now. I don't like const's. They are a nuisance. You can't
directly pass string literals to them you want to change. Maybe that's just
the way C is though.
#include <stdio.h>
#include <stdlib.h>
int comp(constvoid *a,const void *b)
{
int *ia=(constint *)a;
int *ib=(const int *)b;
return *ia-*ib;
}
void print_int_array(int *array,size_t len)
{
size_t i;
for (i=0;i<len;i++)
printf("%d | ",array);
putchar('\n');
}
void sort_int(void)
{
int num={1,3,6,4,5};
size_t num_len=sizeof num/sizeof (int);
}
1 because of qsorts comp callback function parameters include a const do I
need them and can I remove them as I have in the callback?
2. second line of sort_int. num is not a built in type so it doesn't require
parenthesis does it?
Bill
them. This is for qsort. I tried to tackle this once and couldn't get it I
think I get it now. I don't like const's. They are a nuisance. You can't
directly pass string literals to them you want to change. Maybe that's just
the way C is though.
#include <stdio.h>
#include <stdlib.h>
int comp(constvoid *a,const void *b)
{
int *ia=(constint *)a;
int *ib=(const int *)b;
return *ia-*ib;
}
void print_int_array(int *array,size_t len)
{
size_t i;
for (i=0;i<len;i++)
printf("%d | ",array);
putchar('\n');
}
void sort_int(void)
{
int num={1,3,6,4,5};
size_t num_len=sizeof num/sizeof (int);
}
1 because of qsorts comp callback function parameters include a const do I
need them and can I remove them as I have in the callback?
2. second line of sort_int. num is not a built in type so it doesn't require
parenthesis does it?
Bill