我一直在尝试将一个Java程序转换为C语言,这是一个手表模拟器,我使用Ascii艺术来显示时间。我已经将所有数字(0-9)存储在二维字符数组中(例如:9):
char nine[7][5] = {
{ '0', '0', '0', '0' },
{ '0', ' ', ' ', '0' },
{ '0', ' ', ' ', '0' },
{ '0', '0', '0', '0' },
{ ' ', ' ', ' ', '0' },
{ ' ', ' ', ' ', '0' },
{ ' ', ' ', ' ', '0' }
};
我现在有一个函数,其工作是将存储在int数组中的时间转换(例如22:04:59,将存储为220459的数组)。该函数应返回与每个数字对应的Ascii艺术品,以便最终可以调用打印时间的函数(以ascii形式),该函数需要采用6个char [] []参数。
简而言之,我需要知道使用哪6个参数调用此函数:
void printScreen(char hourFirstDigit[7][5], char hourSecondDigit[7][5], char minuteFirstDigit[7][5], char minuteSecondDigit[7][5], char secFirstDigit[7][5], char secSecondDigit[7][5])
在Java中,我的解决方案很简单,只需编写一个返回char[][]数组的函数,然后使用一个switch语句来处理10个情况(0-9),以下是前几行代码:
char timeToAsciiArt[][](int digitNumber, int small) {
switch (timeRightNow[digitNumber]) {
case 0:
return zero;
}
可能的解决方案: 我读到至少有两种可能的解决方案(一般情况下),1. 用数组指针替换。2. 用结构体包装。
我的想法: 1. 我真的不确定如何返回一个指向数组的指针(可以有人给出例子吗?:)。
char (*timeToAsciiArt(int, int))[7][5] {switch(/**/){case 0: return &zero;}}
。或者:char (*timeToAsciiArt(int, int)[5] {switch(/**/){case 0: return zero;}}
。 - EOF