我想寫一個代碼,只使用az生成變量,最多4個字符,這意味着總共26 * 26 * 26 * 26組合。所以這裏是我在做什麼C代碼生成與az和最大4個字符的變量的變量
#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]);
其產生的分段故障。我明白,我可能會做錯的方式。任何機構都可以告訴我我做錯了什麼。
壓痕是一種禮貌讀者 –