小白问题(二维数组问题)
char a ={"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};//为什么这里要用二维数组这段二维数组是如何表示的(图表表示)
#include<stdio.h>
#include<string.h>
#define N 10
#define M 12
main()
{
int i=0;
int j=0;
int k=0;
char str ={0};
char a ={"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};//为什么这里要用二维数组
char b ={"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
do
{
strcpy(str,a);
strcat(str,b);
k++;
printf(k%10!=0?"%-6s":"%-6s\n",str,str);
i++;
if(i==N)i=0;
j++;
if(j==M)j=0;
if(i==0 && j==0) break;
}while(1);
printf("%d\n",k);
} 因为你用的数组是 char 类型,而中文字是宽字符(后面那个 8 表示中文字符最大能储存大小,不是字符数量)
char a ={"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"} 如同 char b = {"banana", "apple", "potato", "happy"}
页:
[1]