I am practicing a 2 dimensional array.
Although I want to assign a set of numbers to a row by row, which of 2 dimensional array has already been made, my code can not be compiled.
How can I achieve my purpose, and what is my mistake?
Thank you for your reading my question.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int **animation;
int rows = 3;
int cols = 7;
int y, x;
int frame;
animation = (int **) malloc(rows * sizeof(int *));
if (animation == NULL) {
puts("array animation rows: allocation failure!");
return 1;
}
for (y = 0; y < rows; y = y + 1) {
animation[y] = (int *) malloc(cols * sizeof(int));
if (animation[y] == NULL) {
printf("array animation[%d]: allocation failure!", y);
return 1;
}
}
int animation[0] = {0, 40, 48, 118, 48, 41, 0};
int animation[1] = {40, 48, 118, 48, 41, 0, 0};
int animation[2] = {40, 48, 118, 48, 41, 0, 0};
for (frame = 0; frame != 3; frame = frame + 1) {
printf("%s\n", animation[frame]);
}
for (y = 0; y < rows; y = +1) {
free(animation[y]);
}
free(animation);
return 0;
}