Hi guys, need another time your help..
At the moment i have to write a program what is dealing with the stack memory.. but that does not really matter, i actually have a mistake with my for loop..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct TStack
{
char Daten[100];
struct TStack *Next;
};
struct TStack *Keller = NULL;
void Push(char *Daten)
{
struct TStack *Element;
Element = (struct TStack *) malloc(sizeof(struct TStack));
strcpy(Element->Daten, Daten);
Element->Next = Keller;
Keller = Element;
}
void Pop(char *Resultat)
{
struct TStack *Element;
if (Keller == NULL)
printf("Der Keller ist leer!\n");
else
{
strcpy(Resultat, Keller->Daten);
Element = Keller;
Keller = Keller->Next;
free(Element);
}
}
int main(void) {
char str[100];
int n, i;
char satz[30];
printf("\nWie viel Zeichensaetze wollen Sie eingeben?");
scanf("%i",&n);
for(i=0; i<n; i++)
{
printf("\nGeben Sie ihren %i.Zeichensatz ein: ",(i+1));
fgets(satz, 30, stdin);
Push(satz);
}
while (Keller != NULL)
{
Pop(str);
printf("%s\n",str);
}
return(0);
}
The mistak is, that the for loop, always skips the first step. Hope you understand my english und furthermore you can help me..
much greetings