ok i got a little farther, will somebody please help me out, it would be greatly appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void swap(void *e1, void *e2, size_t size);
void bubblesort(void *base, size_t n, size_t size,
int (*cmp)(const void *el1, const void *el2));
int array[20];
int i,n,c=0;
int main(int argc, char * argv[])
{
int array[20];
int i;
for (i=0; i<20; i++)
array[i] = i;
srand( (unsigned)time( NULL ) );
for (i=0; i<20; i++)
{
array[i]= rand()%1000;
}
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
if (argv[i][1] == 'a'){
void bubblesort();
for( i=0; i<20; i++)
printf("%d\n",array[i]);
}
else if (argv[i][1] == 'd')
{
void bubblesort();
for( i=0; i<20; i++)
printf("%d\n",array[i]);
} else printf ("Unknown switch %s\n", argv[i])
else if (strcmp(argv[i], "name") == 0)
puts ("Found name");
}
return(0);
}
void bubblesort(void *base, size_t n, size_t size,
int (*cmp)(const void *el1, const void *el2))
{
size_t i, sorted = 0;
char *p = (char *) base;
while(!sorted)
{
sorted = 1;
for(i = 0;i < n-1; i++)
{
if(cmp(p+(i*size),p+((i+1)*size))>0)
{
swap(p+(i*size),p+((i+1)*size),size);
sorted = 0;
}
}
}
}
void swap(void *e1, void *e2, size_t size)
{
char buf[256], *p1 = (char *)e1, *p2 = (char *)e2;
size_t ms;
for(ms = size; 0< ms; )
{
size_t m = ms < sizeof(buf)?ms:sizeof(buf);
memcpy(buf,p1,m);
memcpy(p1,p2,m);
memcpy(p2,buf,m);
ms -= m, p1+=m, p2+=m;
}
return;
}
int cmp(const void *e1, const void *e2)
{
int *i1 = *(int **)e1, *i2 = *(int **)e2;
return (*i1<*i2)?-1:(*i1!=*i2);
}