I would like to know how I can store the return of the function below, which generates a random string, into a vector of strings with 100 of those words generated by the function, then to do an ascending and descending ordering in the vector.
char* geraStringAleatoria(){
char *validchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *novastr;
register int i;
int str_len;
// novo tamanho
str_len = (rand() % MAX_STR_SIZE );
// checa tamanho
str_len += ( str_len < MIN_STR_SIZE ) ? MIN_STR_SIZE : 0;
// aloca memoria
novastr = ( char * ) malloc ( (str_len + 1) * sizeof(char));
if ( !novastr ){
printf("[*] Erro ao alocar memoria.\n" );
exit ( EXIT_FAILURE );
}
// gera string aleatória
for ( i = 0; i < str_len; i++ ) {
novastr[i] = validchars[ rand() % strlen(validchars) ];
novastr[i + 1] = 0x0;
}
return novastr;
}
In the main function I can assign the function return to a string:
int main() {
char *str;
str = geraStringAleatoria();
return 0;
}
But I do not know how to store each word generated in a string vector, as if each vector position were a word.