SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 4 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 18 Nov 2017 My Price 10.00

program prompts user to enter a line of text up to 50 characters.

Hello, I am once again in need of a tutor in C Programming class.  I have attached the problem I am working on.  If you are able to help me, I'll show you what I have done so far.

  • /* ----------------------------------------------------------------------------------------------
          Program           : uprlwr.c
          Course            : 90.212
          Assignment        : Assignment #4 - Array Notation
          Objective         : This program prompts user to enter a line of text up to 50 characters.
                              It then outputs the line of text in uppercase and then in lowercase.
    ------------------------------------------------------------------------------------------------- */

    #include <stdio.h>
    #include <ctype.h>
     
    /* Function prototypes */
    /* ------------------- */

    void safer_gets (char array[], int max_chars);

    /* Begin function main */
    /* ------------------- */

    main()
    {

          /* Declare variables */
          /* ----------------- */

          char  text[51];
          int   i;


          /* Prompt user for line of text */
          /* ---------------------------- */


          printf ("\nEnter a line of text (up to 50 characters):\n");

          safer_gets(text,50);

     
          /* Convert and output the text in uppercase characters. */
          /* ---------------------------------------------------- */

          printf ("\nThe line of text in uppercase is:\n");

    ->    i = 0;
    ->    while ( text[i] != '\0')            /* could have been: while ( text[i] ) */
    ->          putchar( toupper(text[i++]) );
     

          /* Convert and output the text in uppercase characters. */
          /* ---------------------------------------------------- */

          printf ("\n\nThe line of text in lowercase is:\n");

    ->    i = 0;
    ->    while ( text[i] != '\0')            /* could have been: while ( text[i] ) */
    ->          putchar( tolower(text[i++]) );


         /* Add carriage return and pause output */
         /* ------------------------------------ */

         printf("\n");
         getchar();
        
    } /* end main */


    /* Function safer_gets */
    /* ------------------- */


    void safer_gets (char array[], int max_chars)
    {
      /* Declare variables. */
      /* ------------------ */

      int i;

      /* Read info from input buffer, character by character,   */
      /* up until the maximum number of possible characters.    */
      /* ------------------------------------------------------ */

      for (i = 0; i < max_chars; i++)
      {
         array[i] = getchar();


         /* If "this" character is the carriage return, exit loop */
         /* ----------------------------------------------------- */

         if (array[i] == '\n')
            break;
     
       } /* end for */

       /* If we have pulled out the most we can based on the size of array, */
       /* and, if there are more chars in the input buffer,                 */
       /* clear out the remaining chars in the buffer.                      */
       /* This is equivalent to the fflush() function.                      */
       /* ----------------------------------------------------------------  */

       if (i == max_chars )

         if (array[i] != '\n')
           while (getchar() != '\n');

       /* At this point, i is pointing to the element after the last character */
       /* in the string. Terminate the string with the null terminator.        */
       /* -------------------------------------------------------------------- */

       array[i] = '\0';
     

    } /* end safer_gets */

Attachments:

Answers

(5)
Status NEW Posted 18 Nov 2017 10:11 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)