Der Compiler meckert!
-
also fehler ist das nicht aber schön ist auch was anderes...
void appendChar(charListT *clist, char c){ ... while(aktuell->next != NULL) { aktuell=aktuell->next; } ... }
stell dir mal vor deine liste hat 100 elemente und du fügst 2 ein dann mußt ca 200x die schleife durchlaufen, merk dir doch das letzte element? dann ist das immer gleich schnell
noobLolo
-
Meinst du ich soll in der Schleife aktuell auf Null zeigen lassen?
aktuell=aktuell->NULL?
-
struct list{ struct element* head;//das erste struct element* foot;//das letzte }; statt struct list{ struct element* head; };
naturlich mußt du den zeiger auf das letzte element immer ändern aber das ist viel besser als deine schleifen lösung
-
Das gehört zu den Vorgaben. Die sollen wir nicht verändern. Wir schreiben quasi nur die Funktionen.
Mein Problem ist geblieben. Der Compiler zeigt weder linker noch Quelltextfehler an. Die exe.Datei funktioniert trotzdem nicht. Ich kapier es einfach nicht.Hat jemand nen Tipp?
Ich weiß nicht warum es nicht funzt.
-
post doch mal alles
dann kann ich mal schauen ob ich es bei mir zum laufen bekomm
-
#ifndef CHARLIST_H #define CHARLIST_H struct element{ char cont; //information part struct element* next; //organization part }; struct list{ struct element* head; }; typedef struct element charElemT; typedef struct list charListT; /* initialises the list by setting first to NULL */ void init(charListT* clist); /* returns the number of listelements */ int length(charListT* clist); /* prints the characters stored in clist as a string to stdout */ void print_liste(charListT *clist); /* creates a new listelement with the character c and appends to clist */ void appendChar(charListT *clist, char c); //mit malloc speicher reservieren; (char ElemT*) malloc(sizeof(charElement)) /* creates a new listelement with character c inserts the listelement at position pos if pos < length otherwise it appends the listelement */ void insertChar(charListT* clist, char c, int pos); /* removes the listelement at position pos and returns 1 if pos is withis 0 and length-1 otherwise it returns -1 */ int removeAtPosition(charListT* clist, int pos); /* removes all listelements */ void clear(charListT *clist); #endif #include <stdio.h> #include "charList.h" #include <stdlib.h> int main() { char c1 = 'A'; char c2 = 'a'; int i = 0; charListT liste; init(&liste); for(;c1 <'G'; c1++) { appendChar(&liste, c1); } printf("%i ",sizeof(struct list)); print_liste(&liste); int len = length(&liste); printf("Laenge der Liste %d\n\n", len); int pos = 0; for(;c2 < 'g';c2++){ insertChar(&liste, c2, pos); pos = pos +2; } print_liste(&liste); len = length(&liste); printf("Laenge der Liste %d\n\n", len); for (i = len-2; i >=0; i= i-2) { removeAtPosition(&liste, i); } //*removeAtPosition(&liste, 10); print_liste(&liste); len = length(&liste); printf("Laenge der Liste %d\n\n", len); // clear(&liste); print_liste(&liste); system("PAUSE"); return 0; } #include<stdlib.h> #include<stdio.h> #include "charList.h" void init(charListT* clist) { clist->head = NULL; } int length(charListT* clist) { } void print_liste(charListT *clist) { charElemT* wurst = clist->head; while(wurst != NULL) { printf("%s", wurst->cont); wurst = wurst->next; } } void appendChar(charListT *clist, char c) { charElemT* wurst =(charElemT*)malloc(sizeof(charElemT)); wurst->cont =c; wurst->next=NULL; if( clist->head == NULL) { clist->head= wurst; return; } charElemT* aktuell = clist->head; while(aktuell->next != NULL) { aktuell=aktuell->next; } aktuell->next=wurst; return; } void insertChar(charListT* clist, char c, int pos) { } int removeAtPosition(charListT* clist, int pos) { } void clear(charListT *clist) { }
-
der haupt fehler liegt erstmal in z.121
printf("%s", wurst->cont);
wurst->cont ist ein char und kein char* aka "string" also machst du am besten
printf("%c", wurst->cont);
sonst stürzt es dir immer ab da du versuchst auf etwas zuzugreifen was nicht da ist
lg lolo
-
axo ja zu test zwecken kannst du auf die schnelle
int length(charListT* clist) { return 0; } und int removeAtPosition(charListT* clist, int pos) { return 0; }
machen und als nächstes würd ich die length() function umsetzen sonst wird das alles gefährlich
lg lolo
-
Darf ich dich mal kurz GOTT nennen! Es funzt!
Hatte beim linken auch noch nen Buchstabendreher drinne.
Ich würde dir ja gerne ein alkoholisches Getränk ausgeben. Macht sich halt nur schlecht.
Eine riiiiieeeeeeeesengroßes Dankeschön.
Ich war kurz davor dem Programm die Arme zu brechen.Vielen, Vielen Dank nochmal.
-
man muß es ja nicht gleich übertreiben, freut mich natürlich wenns dir geholfen hat
-
Boa, bloss es wollte einfach nicht und dann ist die Schwelle von "es geht gar nicht" zu "alles klappt super" so eng.
Da ist man doch heilfroh.
Also vielen Dank nochmal und eine geruhsame Nacht.
Ich bin die wirklich dankbar.