This is for a school assignment. The goal of this function is to randomly select a word from each array and create a new array with the first letter of each sentence capitalized, spaces between each word, and a period in the end 20 times. The sentence follows the format article, noun, verb, preposition, article, and noun.
My question is how do I go about capitalizing the first letter of each sentence? I tried to set the first position in the string to equal the char at that position - 32, but that just crashes the program.
void randomize(void) {
char *article[] = {"the", "a", "one", "some", "any"};
char *noun[] = {"boy", "girl", "dog", "town", "car"};
char *verb[] = {"drove", "jumped", "ran", "walked", "skipped"};
char *preposition[] = {"to", "from", "over", "under", "on"};
char *sentence[6];
int running = 1;
while(running){
int location = rand()%5;
char *captFirstLetter = article[location];
captFirstLetter[0] = captFirstLetter[0] - 32 ;
sentence[0] = captFirstLetter;
sentence[1] = noun[rand()%5];
sentence[2] = verb[rand()%5];
sentence[3] = preposition[rand()%5];
sentence[4] = article[rand()%5];
sentence[5] = noun[rand()%5];
for(int i = 0; i < 7; i++){
printf("%s%s%s", (i == 6) ? "" : sentence[i], (i > 4) ? "" : " ", (i == 5)? ".\n" : "" );
}
running ++;
if(running == 21){
running = 0;
}
}
}