I'm trying to write a recursive program that makes/prints a string with each of all the possible combinations of vowels(A, E, I, O, U), that includes at least once every vowel. The number of elements is taken as input from the user (so to include each vowel at least once >=5). I really can't figure out the right way to do this.
Here's my take on it (not working though):
#include <stdio.h>
#include <stdlib.h>
int voc_gen(int n, char *array);
char rand_voc();
int main()
{
char *array, voc[] = "AEIOU";
int i, N;
printf("Insert number of elements for vocals string:\n");
scanf("%d", &N);
array = malloc(N * sizeof(char));
for(i=0; i<5; i++)
array[i] = voc[i];
voc_gen(N-5, array);
return 0;
}
int voc_gen(int n, char *array){
if(n==0)
return 0;
else{
array[voc_gen(n, array)] = rand_voc();
printf("%s\n", array);
return voc_gen(n-1, array);
}
}
char rand_voc(){
char array[] = "AEIOU";
int i;
return array[rand()%5];
}