#1 30. November 2006 [lineare listen]ultra ratlos!!!! servus^^ ihr müsst mir helfen.. ich bin verzweifelt... wir ham jez in der schule lineare listen... wir haben ein struct wo name und telefonnummer eingegeben wird... und wenn wir bei name nix eingeben bricht er ab.. und gibt alles aus... soweit sogut^^ er gibt dann das aus was man als letztes eingegeben hat.. dann das was man davor bis dahin was man als erstes eingegeben hat.... so.......... jez sollen wir es so machen... das aber erst das 1. angezeigt wird.. dann das 2. und dann das 3. oder auch letzte... weil er schiebt dann das was man als erstes eingegeben hat nach hinten.. und setzt davor dann das was man als 2. eingibt... u.s.w..... ich bin voll ratlos.. bitte helft mir.... hier is der Quellcode: Code: #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <iostream.h> struct adresse { char name[20]; int tel; struct adresse *pnext; }; struct adresse *pneu; struct adresse *pstart=NULL; char eingabe[20]={'a'}; int tel; main() { cout<<"Name:"; gets(eingabe); while (strlen(eingabe)!=NULL) { pneu=(adresse*) malloc(sizeof(adresse)); if (eingabe!=NULL) { strcpy(pneu->name,eingabe); cout<<"Telefonnummer:"; cin>>tel; pneu->tel=tel; pneu->pnext=pstart; pstart=pneu; cout<<"Name:"; gets(eingabe); } } while (pstart != NULL) { cout<<"Name: "<<pstart->name<<"\t"<<"Telefonnummer: "<<pstart->tel<<"\n"; pstart=pstart->pnext; } getch(); } + Multi-Zitat Zitieren
#2 30. November 2006 AW: [lineare listen]ultra ratlos!!!! versuchs mal mit einer For schleife Bsp musst deine Ergebnisse in ein Arry speichern dim zahl[10] For (int a=0, a>10) { cout << zahl[a] << endl; a++ } + Multi-Zitat Zitieren
#3 30. November 2006 AW: [lineare listen]ultra ratlos!!!! des passt doch gar net zum thema....des hat keinen sinn was du da geschrieben hast sry^^ + Multi-Zitat Zitieren
#4 30. November 2006 AW: [lineare listen]ultra ratlos!!!! Code: #include <cstdlib> #include <iostream> using namespace std; struct Eintrag { char c_Name[20]; int i_Telefon; int i_Nummer; struct Eintrag *p_sNext; struct Eintrag *p_sLast; }; int main(void) { // Variablen char c_Name[20]; bool b_Again = true; int i_ZaehlerEin = 0; struct Eintrag *p_LetzterEintrag; struct Eintrag *p_NeuerEintrag; struct Eintrag *p_Anfang; struct Eintrag *p_Akt; // Los geht's ^^ // Eingabe while(b_Again == true) { i_ZaehlerEin++; p_NeuerEintrag =(Eintrag*) malloc(sizeof(Eintrag)); cout << "Name: "; cin.get(c_Name, 20); strcpy(p_NeuerEintrag->c_Name, c_Name); if(c_Name[0] == 'r' && c_Name[1] == 'a' && c_Name[2] == 'u' && c_Name[3] == 's') { break; } cout << "Telefonnummer: "; cin >> p_NeuerEintrag->i_Telefon; cin.ignore(); p_NeuerEintrag->i_Nummer = i_ZaehlerEin; if(i_ZaehlerEin == 1) { p_Anfang = p_NeuerEintrag; p_NeuerEintrag->p_sLast = NULL; } else { p_NeuerEintrag->p_sLast = p_LetzterEintrag; p_LetzterEintrag->p_sNext = p_NeuerEintrag; } p_LetzterEintrag = p_NeuerEintrag; } // Ausgabe int i_ZaehlerRaus = 0; while(i_ZaehlerRaus != i_ZaehlerEin) { i_ZaehlerRaus++; if(i_ZaehlerRaus == 1) { p_Akt = p_Anfang; } else { p_Akt = p_LetzterEintrag->p_sNext; } cout << endl << "Eintrag Nr.: " << i_ZaehlerRaus << endl << "Name: " << p_Akt->c_Name << endl << "Telefonnummer: " << p_Akt->i_Telefon << endl; p_LetzterEintrag = p_Akt; p_Akt = NULL; } int irgentwas; cin >> irgentwas; } so dat wars müsste eigentlich laufen.. übrigens hat die stl auch ne "list" funktion ^^ die würde das ganze viel einfacher machen... aber da du im lernstadium bist hab ichs nicht reingemacht... mfg thecoolman4rr + Multi-Zitat Zitieren