I need to make a function that will create an int array with a random size and random characters then return it.
Because I can't make the array a global variable as the size is unknown, I created a separate function for that. I then tried to use a pointer to return the array so that I can use it inside the main function to print the int array as a character.
This is the code I have so far but it gives me the error: 'array initializer must be an initializer list or wide string literal'
int length;
void set_length () {
//generates random integer between 8 and 15 which is used as the length of the array[]
length = (rand() % 8 + 8);
}
int * ascii () {
int array[length];
//this is a function that assigns the values into the array
random_values(array, length);
//just to check
for (int i = 0; i < length; i++) {
printf("%c", array[i]);
}
return array;
}
int main () {
//to prevent rand() from producing the same value every time
srand(time(NULL));
set_length();
int password[] = * ascii();
//what i want from this code but instead gives me the error
for (int i = 0; i < length; i++) {
printf("%d", password[i]);
}
}
Any help will be greatly appreciated. Thanks.