Skip to content

Instantly share code, notes, and snippets.

@paranoidxc
Created May 19, 2014 09:42
Show Gist options
  • Save paranoidxc/e56a3cd41b26dddeeaf1 to your computer and use it in GitHub Desktop.
Save paranoidxc/e56a3cd41b26dddeeaf1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Nmax 10
#define Mmax 20
char buf[Mmax];
int M = 0;
int compare(void *i, void *j) {
return strcmp( *(char **)i, *(char **)j );
}
main() {
int i, N;
char* a[Nmax];
for ( N = 0; N < Nmax; N++ ) {
a[N] = &buf[M];
printf("N=%d\n", N);
if ( scanf("%s", a[N]) == EOF ) {
printf("%d\n", N);
break;
}
M += strlen( a[N] )+1;
}
qsort( a, N, sizeof(char*), compare);
for ( i = 0; i < N; i++ ) {
printf("%s\n", a[i] );
}
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment