Fehler im Stack...
- 
					
					
					
					
 Hallo, wollte einen Stack programmieren wo ich spielkarten die sich durch zweidimensionale arrays darstellen lassen jedoch funktioniert dieser net  
 würde mich über jeden tipp und hilfe freuen #include <stdio.h> #include <stdlib.h> typedef struct Element{ int *data; struct Element *next; }Element; int push(Element **stack,int *data); int pop(Element **stack,int **data); int createStack(Element **stack); int deleteStack(Element **stack); int createStack(Element **stack){ *stack=NULL; return 0; } int push(Element **stack,int *data){ Element *elem; elem=(Element*)malloc(sizeof(Element*)); if (!elem) return 1; elem->data=data; elem->next=*stack; *stack=elem; return 0; } int pop(Element **stack,int **data){ Element *elem; elem=*stack; if (!elem) return 1; *stack=elem->next; *data=(elem->data); free(elem); return 0; } int deleteStack(Element **stack){ Element *next; while(*stack){ next=(*stack)->next; free(*stack); *stack=next; } return 0; } void Karte1(int Matrix[5][5]); int main(int argc, char *argv[]){ Element *stack; int MatrixA[5][5] = { }; int x,y,*Karte1 ; MatrixA[2][0] = '+' ; MatrixA[2][1] = '+' ; MatrixA[2][2] = '+' ; for(x=0; x<5; x++) { for(y=0; y<5; y++) { printf("%c", MatrixA[x][y]); } printf("\n"); } void Karte2(int Matrix[5][5]) { int MatrixB[5][5] = { }; int x,y,*Karte2; MatrixB[0][2] = '+'; MatrixB[1][2] = '+' ; MatrixB[2][2] = '+' ; MatrixB[2][3] = '+' ; MatrixB[2][4] = '+' ; MatrixB[3][1] = 'X' ; MatrixB[3][2] = 'X' ; MatrixB[3][3] = 'X' ; MatrixB[4][0] = 'X' ; MatrixB[4][4] = 'X' ; for(x=0; x<5; x++) { for(y=0; y<5; y++) { printf("Karte2: %c", MatrixB[x][y],*Karte2); } printf("\n"); } } void Karte3(int Matrix[5][5]) { int MatrixC[5][5] = { }; int x,y,*Karte3; Matrix[0][0] = 'X'; Matrix[0][4] = 'X'; Matrix[1][1] = 'X'; Matrix[1][2] = 'X'; Matrix[1][3] = 'X'; Matrix[2][0] = '+'; Matrix[2][1] = '+'; Matrix[2][2] = '+'; Matrix[2][3] = '+'; Matrix[2][4] = '+'; Matrix[3][1] = 'X'; Matrix[3][2] = 'X'; Matrix[3][3] = 'X'; Matrix[4][0] = 'X'; Matrix[4][4] = 'X'; for(x=0; x<5; x++) { for(y=0; y<5; y++) { printf("Karte3: %c", MatrixC[x][y],*Karte3); } printf("\n"); } } void Karte4(int Matrix[5][5]) { int MatrixD[5][5] = { }; int x,y,*Karte4 ; Matrix[0][0] = 'X'; Matrix[1][1] = 'X'; Matrix[2][1] = 'X'; Matrix[2][2] = '+'; Matrix[2][3] = '+'; Matrix[2][4] = '+'; Matrix[3][1] = 'X'; Matrix[4][0] = 'X'; for(x=0; x<5; x++) { for(y=0; y<5; y++) { printf("Karte4: %c", MatrixD[x][y],*Karte4); } printf("\n"); } } void Karte5(int Matrix[5][5]) { int MatrixE[5][5] = { }; int x,y,*Karte5; Matrix[0][0] = 'X'; Matrix[1][1] = 'X'; Matrix[2][1] = 'X'; Matrix[2][2] = '+'; Matrix[2][3] = '+'; Matrix[2][4] = '+'; Matrix[3][1] = 'X'; Matrix[4][0] = 'X'; for(x=0; x<5; x++) { for(y=0; y<5; y++) { printf("Karte5: %c", MatrixE[x][y],*Karte5); } printf("\n"); } } void Karte6 (int Matrix[5][5]) { int MatrixF[5][5] = { }; int x,y,*Karte6; Matrix[0][0] = 'X'; Matrix[0][4] = 'X'; Matrix[1][1] = 'X'; Matrix[1][3] = 'X'; Matrix[2][1] = 'X'; Matrix[2][3] = 'X'; Matrix[3][1] = 'X'; Matrix[3][3] = 'X'; Matrix[4][0] = 'X'; Matrix[4][4] = 'X'; for(x=0; x<5; x++) { for(y=0; y<5; y++) { printf("Karte6: %c", MatrixF[x][y],*Karte6); } printf("\n"); } } createStack(&stack); if(push(&stack,&MatrixA[x][y])==1) printf("Error pushing\n"); if(pop(&stack,&MatrixA[x][y])==1) printf("Error poping\n"); return 0; }[edit by rapso]code tags [/edit] 
 
- 
					
					
					
					
 Oh Gott, wo hast du das abgeschrieben? - was ist der Fehler/was funktioniert nicht? 
 - das gehört ins C Forum nicht ins Spieleforum
 - es gibt C/C++ Tags, warum benutzt du die nicht?
 - malloc-Cast == Schrott
 - hast du die Compilerwarnungen abgearbeitet? mit Sicherheit nicht!
 - was sollen die unsinnigen MatrixD usw?
 - leere Initialisierungslisten -> undefiniertes Verhalten == Schrott
 - Dereferenzierung eines uninitialisierten Zeigers -> undefiniertes Verhalten == Schrott
 - ...Da kann überhaupt nichts funktionieren. 
 
- 
					
					
					
					
 um wutz' post nochmal zu einem tipp zusammenzufassen: du musst erstmal programmieren lernen, ohne grundlagen wirst du nicht weit kommen. 
 
