Created
May 19, 2014 09:42
-
-
Save paranoidxc/e56a3cd41b26dddeeaf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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