Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I apply the 'toupper' to capitalize the first word?

Newbie
 
Join Date: Nov 2009
Posts: 1
#1: 2 Weeks Ago
g. 366*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string.h>

int main (void)
{
char *article[5] = {"the", "a", "one", "some", "any"};
char *noun[5] = {"boy", "girl", "dog", "town", "car"};
char *verb[5] = {"drove", "jumped", "ran", "walked", "skipped"};
char *preposition[5] = {"to", "from", "over", "under", "on"};
char sentence[30];


int choice,i,a,a2,n,n2,v,p;
srand(time(NULL));

for(i=0;i<20;i++)
{
sentence[0] = '\0';
a = rand()%5;
n = rand()%5;
v = rand()%5;
p = rand()%5;
a2 = rand()%5;
n2 = rand()%5;

strcat(sentence, article[a]);
strcat(sentence, " ");
strcat(sentence, noun[n]);
strcat(sentence, " ");
strcat(sentence, verb[v]);
strcat(sentence, " ");
strcat(sentence, preposition[p]);
strcat(sentence, " ");
strcat(sentence, article[a2]);
strcat(sentence, " ");
strcat(sentence, noun[n2]);
strcat(sentence, ".\n");


printf ("%c");
}



system("PAUSE");
return 0;
}

Needs Regular Fix
 
Join Date: Jul 2008
Posts: 383
#2: 2 Weeks Ago

re: How do I apply the 'toupper' to capitalize the first word?


Apply it to sentence[0], that is the first letter of the first word in this case.
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#3: 2 Weeks Ago

re: How do I apply the 'toupper' to capitalize the first word?


toupper() converts only one character to upper case. You will need to apply it to all elements of the word.
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 383
#4: 2 Weeks Ago

re: How do I apply the 'toupper' to capitalize the first word?


I suppise the goal is to get a proper English sentence, where the first letter of the first word is capitalized.
Reply


Similar C / C++ bytes