Was sollte ich darüber nachdenken, wenn ich die Ausgabe verstehe? Weil meine Ausgabe im Moment Müll für 20 ganze Zahlen ist und ich weiß nicht warum. Mein Ziel ist es 20 Arrays mit jeweils 30 Integer zu erstellen. So dass die endgültige Anordnung ganze Zahlen von 19 bis 48.Unsicher auf meine Ausgabe in Bezug auf malloc (c)
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int **p;//Declaration of a pointer variable
int i = 0, j;
int rows = 20;
int columns = 30;
p = (int**)malloc(20 * sizeof(int)); //First "bookend" allocates space
printf("Hello World! I have created a dynamic 20-array of 20x30 integers!\n");
if (p == NULL)
{
printf("Failed to allocated memory!");
exit(1);
}
for (i = 0; i < 20; i++)
{
if (p[i] == NULL)
{
printf("Integers not allocated! ");
}
p[i] = (int**)malloc(20 * sizeof(int));
}
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
{
if (p[j] == NULL)
{
printf("Integers not allocated! ");
}
p[i][j] = (int *)malloc(40 * sizeof(int));
}
printf("%d\n", p[(i+1)+j]);
}
free(p);
return 0;
}
Hinweis: '20! = 30' ... und' 20! = 40' – wildplasser
Vielen Dank. Ich drucke immer noch Adressen. (Ich habe die extra for-Schleife gelöscht) –