Ask Question

Write a program to convert a string (of up to 20 characters, including the terminating null character) to all uppercase characters. After getting a string that could include spaces (use the fgets () function and don't forget to strip off the ending if it is there), display the original string. Pass the string to a void function (since the 'string' is really as character array) and have the function convert the string to all uppercase by iterating through the string using a for loop and the strlen () function (which is part of the string. h library), and using the toupper () function (which is part of the ctype. h library) to convert each character in the string. Then, back in the main program, display the all uppercase string.

+5
Answers (1)
  1. 9 November, 13:20
    0
    Check the explanation

    Explanation:

    #include

    #include

    #include

    void MyToUpper (char * p)

    {

    int i;

    for (i=0; i
    {

    p[i]=toupper (p[i]);

    }

    }

    int main (void) {

    char str[20];

    printf ("Enter a string:");

    fgets (str, 20, stdin);

    printf ("The string you entered was: %s/n", str);

    MyToUpper (str);

    printf ("The string converted to uppercase is: %s/n", str);

    fflush (stdin);

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program to convert a string (of up to 20 characters, including the terminating null character) to all uppercase characters. After ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers