As I understand it, you want:
- Some kind of repository for your ASCII art;
- A function that receives a digit and returns some pointer to the corresponding ASCII store,
- A function that receives an ASCII art set and prints them.
Conservation of ASCII Art
It would be wise to wrap your ASCII art in a structure, since then you could store more data about it. You might want to get a finer number 1 in the future; you will need to store the size data of each ASCII art:
struct ascii_digit { unsigned int width; unsigned int height; char[MAX_HEIGHT][MAX_WIDTH] art;
Of course, if you absolutely don't plan on having anything other than a fixed size, the arrays are fine.
Finding the Right ASCII Art
When passing arrays to C, you usually don't pass the array directly: you usually use a pointer to it. Thus, the correct prototype for your function will not be
char time_to_ascii_art[][](int digit_number, int small);
but if you use structures
struct ascii_digit* time_to_ascii_art(int digit_number, int small);
Note that we are returning a pointer to a structure. Although it is absolutely impossible to directly transfer a structure, it cannot be considered good practice, since it causes some overhead depending on the size of your structure.
or you can use a naive approach with char pointers:
char* time_to_ascii_art(int digit_number, int small);
Note that if you have a char* pointer for a two-dimensional array, you will have to do the math yourself when trying to access its contents. For example, access to the yth member of the string x th: array[width * x + y] . To get rid of this, you can use pointers for arrays:
char (*time_to_ascii_art)(int digit_number, int small)[ASCII_ART_WIDTH];
In this function, you can either use the switch β¦ case , as in Java (an example using structures):
// Let say that your structures are declared in the global scope as ascii_zero, ascii_one⦠struct ascii_digit* time_to_ascii_art(int digit_number, int small) { switch(digit_number) { case 0: return ascii_zero; case 1: return ascii_one; default: return NULL; } }
or you could probably be a good idea in Java to have an array containing your ASCII arts, or a pointer to them indexed so that access to the n th element gives you ASCII art for the digit n :
Passing ASCII Art to a Display Function
Now, to pass your ASCII skills to your display function, you can - depending on the data type you choose - either use pointers to structures:
void print_screen(struct ascii_digit* hour_first_digit, β¦);
points to char :
void print_screen(char* hour_first_digit, β¦);
or pointers to an array of characters:
void print_screen(char (*hour_first_digit)[ASCII_ART_WIDTH], β¦);