My code here will always generate one string of length MAXLEN but then start generating strings with a lower length. I'm not certain of why this is happening.
void generate_strings(int n) {
char genvals[] = "abcdefghijklmnopqrstuvwxyzABC"
"DEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
char str[MAXLEN + 1];
int i = 0, j = 0;
for (i = 0; i < n; i++) {
for (int j = 0; j < MAXLEN; j++) {
str[j] = genvals[rand() % strlen(genvals) - 1];
}
str[MAXSTRLEN] = '\0';
printf("%s\n", str);
memset(str, 0, MAXLEN);
}
}
Aucun commentaire:
Enregistrer un commentaire