Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 33 lines (27 sloc) 0.593 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/* http://www.reddit.com/r/dailyprogrammer/1epasu/ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compare(const void *a, const void *b)
{
int c = *(const int *)a;
int d = *(const int *)b;

if ( c > d)
return 1;
else if ( c < d)
return -1;
else
return 0;
}

int main(int argc, char **argv)
{
int i;
int A[] = { 692, 1, 32, };
int B[] = { 0, 0, 0, 14, 15, 123, 2431, };

memcpy(B, A, sizeof(A));
qsort(&B[0], sizeof(B)/sizeof(B[0]), sizeof(int), compare);

for (i = 0; i < sizeof(B)/sizeof(B[0]); i++)
printf("%d ", B[i]);

putchar('\n');
return (0);
}
Something went wrong with that request. Please try again.