【发布时间】:2015-12-04 03:46:09
【问题描述】:
我正在处理的功能有问题。我能够获得正确的数据,但也不能打印出月份的名称。
我得到的示例输出:
| Month | High | Low | Avg | Precip |
|-----------|-------|-------|-------|---------|
1 | 9.8 | -26.2 | -7.8 | 55.3 |
2 | 7.5 | -23.3 | -8.6 | 33.1 |
3 | 14.2 | -19.6 | -4.7 | 33.2 |
4 | 23.7 | -5.3 | 6.2 | 56.8 |
5 | 33.0 | -0.6 | 13.9 | 62.7 |
6 | 32.1 | 8.0 | 19.7 | 69.7 |
7 | 34.9 | 12.6 | 22.2 | 181.8 |
8 | 31.5 | 11.0 | 20.9 | 69.2 |
9 | 34.1 | 5.0 | 16.1 | 69.0 |
10 | 24.8 | -2.9 | 10.8 | 56.9 |
11 | 16.0 | -12.8 | 2.1 | 36.2 |
12 | 15.6 | -17.8 | -4.2 | 65.8
我想将数字 1-12 转换为正确的月份名称。即:1 = 一月。
void printMonthlyStatistic(int month,const struct MonthlyStatistic* monthly)
是函数的样子
for(i=0;i<12;i++){
printMonthlyStatistic(i+1,&monthly[i])
并且在 main 中被调用。
任何关于在哪里寻找合适的方法来完成这项工作的帮助都会很棒。谢谢!
【问题讨论】:
-
提示:使用数字作为数组的索引。
-
switch (month)?或者更好的是,有一个月份名称字符串数组,其中索引是月份 int 值。 -
这就是
strftime()的用途。