【发布时间】:2015-01-18 19:58:50
【问题描述】:
我想用 C 语言运行一个 For 循环来连接然后将结果复制到一个新数组中。
// Simple array with numbers to be appended at the end of the array "type" below
char numbers[20][2]={"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"};
//after each of these words i want to append the number found above.
char type[10][30]={"rizi","makaronia","kafes","giaourti","feta","avga","sampuan","rouxa","aporipantiko","aposmitiko"};
//This is the array i wish to add the results. This way i will create 20 of each type
char random_type [20][30];
int i,j;
for(i = 0; i < 10; i++)
{
for (j = 0; i < 20; j++)
{
strcpy(random_type[i][j],type[j]);
}
}
【问题讨论】:
-
"10" 不适合
char[2]数组,因为终止的零字节。 -
我不清楚
random_type的元素的期望值是什么。 -
无限循环->
for (j = 0; i < 20; j++),还有random_type[i][j]是什么? -
@Jasper 我已经设置了字符数[20][2],我已经看到它很适合这样。不是吗?
-
长度为 2 的字符串需要一个大小为 3 的 char 数组来包含它,以及它的终止符。