我正在尝试编写一个仅使用 az 和最多 4 char 生成变量的代码,这意味着总共 26*26*26*26 组合。所以这就是我正在做的
#include<stdio.h>
static char vcd_xyz[4];
static char vcd_xyz1[2];
int main()
{
int i,j;
for(i=0;i<26;i++)
{
vcd_xyz[1] = 'a'+i;
printf("%d generated variable is initial is = %c \n",i,vcd_xyz[1]);
for(j=0;j<26;j++)
{
vcd_xyz[2] = 'a'+j;
printf("%d generated variable is = %c \n",j,vcd_xyz[2]);
//strcat(vcd_xyz[1],vcd_xyz[2]);
}
}
return 0;
}
所以它让我产生了这样的东西
0 generated variable is initial is = a
0 generated variable is = a
1 generated variable is = b
2 generated variable is = c
3 generated variable is = d
4 generated variable is = e
5 generated variable is = f
6 generated variable is = g
7 generated variable is = h
8 generated variable is = i
9 generated variable is = j
10 generated variable is = k
11 generated variable is = l
12 generated variable is = m
13 generated variable is = n
14 generated variable is = o
现在我要做的是连接这两个字符,这样我就可以得到这样的组合,aa,ab,ac,ad......ba,bb,bc,bc......ca,cb ......等等,但是当我使用
strcat(vcd_xyz[1],vcd_xyz[2]);
它会产生分段错误。我知道我可能会以错误的方式进行操作。任何人都可以告诉我我在哪里做错了。