#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void bubblesort (int size, char **p_dataarray) {
char *temp = malloc(1000);
for (int i=0; i<size-1; ++i){
for (int j=0; j<size-i-1; ++j){
if (strcmp(p_dataarray[j],p_dataarray[j+1])>0) {
strcpy(temp,p_dataarray[j]);
strcpy(p_dataarray[j],p_dataarray[j+1]);
strcpy(p_dataarray[j+1],temp);
}
}
}
free(temp);
}
int main()
{
char **w=0,z[100];
int n=0;
/* Testdatenbeschaffung (Datei mit 1 Wort/Zeile) */
system("sed 's/:.*//' /etc/passwd>/tmp/kuno");
FILE *f=fopen("/tmp/kuno","r");
while( fscanf(f,"%99s",z)==1 ) w=realloc(w,++n*sizeof*w),strcpy(w[n-1]=malloc(strlen(z)+1),z);
fclose(f);
for(int i=0;i<n;++i) puts(w[i]);
bubblesort(n,w);
puts("##############################################");
for(int i=0;i<n;++i) puts(w[i]);
while(n--) free(w[n]); free(w);
return 0;
}