-3
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include <ctype.h>
    #define SIZE 5

    void select_word(const char *const art[],  const char *const noun[],
                           const char *const verb[], const char *const prep[]);

    void build_sentence(const char *const sentence[]);

    int main()
    {
       int i;
       const char *art [SIZE] = { "the", "a", "one", "some", "any",};
       const char *noun[SIZE] = { "boy", "girl", "dog", "town", "car",};
       const char *verb[SIZE] = { "drove","jumped", "ran", "walked", "skipped",};
       const char *prep[SIZE] = { "to", "from", "over", "under", "on",};
       srand(time(0));
       for(i=0; i<3; i++)
       select_word( art, noun, verb, prep );
       return 0;
    }

    void select_word(const char *const art[],  const char *const noun[],
                           const char *const verb[], const char *const prep[])
    {
           const char *sentence [6] = {

                  art  [rand() % SIZE],
                  noun [rand() % SIZE],
                  verb [rand() % SIZE],
                  prep [rand() % SIZE],
                  art  [rand() % SIZE],
                  noun [rand() % SIZE]};

                  build_sentence(sentence);
       }

       void build_sentence (const char *const sentence[]) {
                          printf( "%s %s %s %s %s %s. \n",
                            sentence [0], 

/* I am attempting to use the 'toupper' function to make the the first word in a randomly generated sentence be upper-case. I think I put a printf function between sentence [0] and sentence [1] */

                            sentence [1], 
                            sentence [2],
                            sentence [3],
                            sentence [4],
                            sentence [5]);
                        }
  • 2
    What is the question ? – cosmos Apr 13 '15 at 20:51
  • What is the question? It is a bunch of badly formatted code. – Eugene Sh. Apr 13 '15 at 20:51
  • Please re-write this into a form of a question so that we can understand what the issue is that you are having. – John Odom Apr 13 '15 at 20:54
  • I didn't intend to have my comment breakup the code, but that was the only way I could post the question. I want to use the 'toupper' function to capitalize the first word of my randomly generated sentence but I'm not sure where to call the function. – akloady252 Apr 13 '15 at 20:55
  • Forgive me, I'm only taking my first programming course ever. How do I call the toupper function to capitalize the first letter of my randomly generated sentence? – akloady252 Apr 13 '15 at 20:57

1 Answers1

2

The problem that you won't be able to use it to your strings in-place, since they are constant. You will need to use some writable storage for the result. If you don't want to, you can uppercase only the first character of the first word and then write the first word starting with the second character right in the printf:

printf( "%c%s %s %s %s %s %s. \n",
                            toupper(sentence[0][0]), 
                            &sentence[0][1], 
                            sentence[1],
                            ..........
Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61