I've written a function in C to get the size of the terminal:
int get_terminal_size()
{
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return w.ws_row * w.ws_col;
}
struct level
{
[...]
char level_data[get_terminal_size()];
}
const int
The size of the array has to be known at compilation time. If you want to allocate memory dynamically you have to use malloc
.
char *level_data = malloc(get_terminal_size());
if (level_data == NULL)
{ /* handle allocation failure */ }
/* ...Do something with your array... */
free(level_data);
People in comments, thank you for the corrections.