我希望创建随机数据进行测试。我想用字母 'A'
填充一个包含 100 个随机长度的字符串数组。
示例:
array[0] = "AAAAA"
array[1] = "AAAAAAAA"
array[2] = "A"
...
char **create_string()
{
char **array = malloc(sizeof(**array));
srand((unsigned int)time(NULL));
int random = 0;
int i, j;
for(int i=0; i<100; i++)
{
random = rand() % 100;
for(j=0; j < random; j++)
{
array[i] = // some sort of string append that would be cheap.
}
}
}
我在查看这个C字符串追加的问题,他们使用了strcat
。有没有更好的方法来解决我的问题?因为我将在循环中运行以创建那些随机大小的字符串。