...
if(argc > 1 && (file = fopen(argv[1], "r")) != NULL)
{
// Gesamten Textinhalt auslesen, bis zum Textendezeichen.
while(fgets(buffer, SIZE, file) != NULL)
{
counter++;
// Wörter einlesen
wort = strtok(buffer, splitt);
// Wörter solange einlesen, wie Wörter über Buffer übergeben werden.
while(wort != NULL)
{
//anhaengen(aktl_Elem, wort, copyString, counter);//, copyZahl);
sort(aktl_Elem, wort, copyString, counter);//, compare);
wort = strtok(NULL, splitt);
}
}
fclose(file);
}
...
node* sort(node* list, void* neuer_String, void* (*set)(void*), int counter)//, int (*cmp)(void*, void*))
{
node* kopf = list;
node* aktl_Elem = list;
node* neu_Elem = (node*) malloc(sizeof(node));
// Überprüfen, ob Speicher übergeben worden ist
if(neu_Elem == NULL)
{
printf("\n Listenelement konnte nicht angelegt werden, da kein Speicher vorhanden ist! \n");
exit(1);
}
//******************* Sortierte Listeneingabe ****************************
//Wenn Liste leer ist, Liste mit ersten Wort befüllen
if(kopf == (aktl_Elem = aktl_Elem -> right))
{
void* tmpchar = set(neuer_String);
neu_Elem -> content = tmpchar;
neu_Elem -> lineCounter = counter;
// In die Listen einfügen
neu_Elem -> left = list;
neu_Elem -> right = list -> right;
list -> right-> left = neu_Elem;
list -> right = neu_Elem;
}
else
{
void* tmpchar = set(neuer_String);
char* string1 = (char*) tmpchar; // Wert
char* string2 = neu_Elem -> right = aktl_Elem -> content;
//Wenn nur ein Element in der Liste ist Prüfen
if(kopf == (aktl_Elem = aktl_Elem -> right) )
{
printf("\nIf\n");
if(strcmp(string1, string2) < 0)
{
//string2 = neu_Elem -> left = aktl_Elem -> content;
printf("\n Stelle gefunden: ");
printf(" %s < %s \n", string1, string2);
neu_Elem -> content = string1;
neu_Elem -> lineCounter = counter;
// rechts vom Listenknoten einfügen
neu_Elem -> left = list -> left;
neu_Elem -> right = list;
list -> left-> right = neu_Elem;
list -> left = neu_Elem;
i = 1;
}
else if(strcmp(string1, string2) == 0)
{
//string2 = neu_Elem -> left = aktl_Elem -> content;
printf("\n Stelle gefunden: ");
printf(" %s = %s \n", string1, string2);
neu_Elem -> content = string1;
neu_Elem -> lineCounter = counter;
// rechts vom Listenknoten einfügen
neu_Elem -> left = list -> left;
neu_Elem -> right = list;
list -> left-> right = neu_Elem;
list -> left = neu_Elem;
i = 1;
}
}
// Wenn mindestens 2 Elemente in der Liste sind mit Schleife alle Elemente der Liste prüfen
while(kopf != (aktl_Elem = aktl_Elem -> right))
{ printf("\nSchleife\n");
string2 = neu_Elem -> left = aktl_Elem -> content;
if (strcmp(string1, string2) < 0)
{
//string2 = neu_Elem -> left = aktl_Elem -> content;
printf("\n Stelle gefunden: ");
printf(" %s < %s \n", string1, string2);
neu_Elem -> content = string1;
neu_Elem -> lineCounter = counter;
// lings vom Listenknoten einfügen
neu_Elem -> left = list -> left;
neu_Elem -> right = list;
list -> left-> right = neu_Elem;
list -> left = neu_Elem;
}
else if(strcmp(string1, string2) == 0)
{
//string2 = neu_Elem -> left = aktl_Elem -> content;
printf("\n Stelle gefunden: ");
printf(" %s = %s \n", string1, string2);
neu_Elem -> content = string1;
neu_Elem -> lineCounter = counter;
// links vom Listenknoten einfügen
neu_Elem -> left = list -> left;
neu_Elem -> right = list;
list -> left-> right = neu_Elem;
list -> left = neu_Elem;
}
else if(strcmp(string1, string2) > 0)
{
printf("\n Stelle nicht gefunden: ");
printf(" %s > %s \n", string1, string2); //return;
}
}
}
return neu_Elem;
}