Okay, so this is my current code:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
struct Display {
int width;
int height;
char **array;
};
struct Display *display_create(int width, int height) {
struct Display *display = (struct Display *) malloc(sizeof(struct Display));
display->width = width;
display->height = height;
display->array = (char **) malloc(sizeof(char) * height);
for (int i = 0; i < height; i += 1) {
display->array[i] = (char *) malloc(sizeof(char) * width);
}
return display;
}
void display_destroy(struct Display *display) {
for (int i = 0; i < display->height; i += 1) {
free(display->array[i]);
}
free(display->array);
free(display);
}
void display_clear(struct Display *display) {
for (int i = 0; i < display->height; i += 1) {
for (int j = 0; j < display->width; j += 1) {
display->array[i][j] = 'X';
}
}
}
void display_render(struct Display *display) {
for (int i = 0; i < display->height; i += 1) {
printf("%s\n", display->array[i]);
}
}
int main(int argc, char **argv) {
struct Display *myDisp = display_create(10, 10);
printf("Display Created\n");
display_clear(myDisp);
printf("Cleared\n");
display_render(myDisp);
printf("Rendered\n");
display_destroy(myDisp);
printf("Destroyed\n");
return 0;
}
And it shows Display Created
and then Windows says not responding. I am newer to C coming from a Java, Python, and C++ background.
I am currently learning C on my own, so if you guys have any book suggestions or tutorials it would be much appreciated. Thanks :) and Happy New Year!