Themen-Überblick
(Aktualisieren)
| Autor |
Nachricht |
rapso
|
um wutz' post nochmal zu einem tipp zusammenzufassen: du musst erstmal programmieren lernen, ohne grundlagen wirst du nicht weit kommen. |
|
|
 |
Wutz
|
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. |
|
|
 |
RoterFuchs
|
| 18:49:22 01.08.2012 Titel: |
Fehler im Stack... |
Zitieren |
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
| C++: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | #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] |
|
|
 |
|
|
|
|
|