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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seversjh
    New Member
    • Nov 2009
    • 1

    #1

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

    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;
    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Apply it to sentence[0], that is the first letter of the first word in this case.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      toupper() converts only one character to upper case. You will need to apply it to all elements of the word.

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

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

        Comment

        Working...