will be helpful for those in need It seems you want to have all the combinations of two characters as strings in an array. BTW: this is not random.
A solution could look like this:
int main(int argc, char *argv[]) {
string key[] = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"V", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
"r", "s", "t", "u", "v", "x", "y", "z"};
//num is the number of elements in the array
int num = sizeof(key) / sizeof(key[0]);
//dynamically allocate memory for it
char *combi = malloc(num * num * (sizeof(char) * 3));
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
char *buf = combi + (i * num + j) * (sizeof(char) * 3);
sprintf(buf, "%s%s", key[i], key[j]);
}
}
//verify the result
int counter = 0;
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
char *combination = combi + (i * num + j) * (sizeof(char) * 3);
printf("[%d]: %s\n", counter++, combination);
}
}
//free the dynamically allocated memory
free(combi);
return 0;
}
[0]: AA
[1]: AB
[2]: AC
...
[2498]: zy
[2499]: zz
char *secondString = combi + 3;
printf("%s\n", secondString);