I'm trying to create an array of 100 strings of random sies between 3 and 10 letters long in C but I'm having a bit of trouble. This is what I have so far...
int main(){
int count, number;
char *randomWord[100]; // 1-d array of pointers to char
char randomLetter;
int wordLength;
// generate 100 strings or random sizes between 3 and 10 letters
for(count = 0; count < 100; count++)
{
wordLength = ((rand() % 10) + 3); // get random size of word
randomWord[count] = malloc(wordLength + 1); // allocated space for word
for(number = 1; number < wordLength; number++)
{
randomLetter = 'A' + (rand() % 26);
//randomWord[count] =
printf("%d\n", randomLetter);
}
printf("%d\n", &randomWord[count]);
}
}
The output I get looks like this...
72
90
82
73
87
75
66
65
6356712
88
66
71
70
67
66
67
69
89
72
74
6356716
71
73
88
87
6356720
Any help or direction would be appreciated.
Aucun commentaire:
Enregistrer un commentaire