INTRO TO C Write a program that inputs a line of text with t
INTRO TO C
Write a program that inputs a line of text with the function fgets() into char array s[100]. Output the line in both uppercase and lowercase letters. Input string \"abcd1234ABCD\" to test your program
Solution
#include <stdio.h>
 #include <ctype.h>
int main()
 {
 int i;
 char s[100];//char array to store the string
 printf(\"Enter the string:\ \");
 // s is the char array, sizeof(s) gives the size of the char array s, stdin is the standard input defined in stdio.h
 fgets(s,sizeof(s),stdin); // to get the input from the user using fgets
 printf(\"Uppercase:\ \");
 //loop to convert the string to uppercase
 for (i = 0; i < sizeof(s); i++)
    {
        s[i]=toupper(s[i]);
    }
    printf(\"%s\", s);
    printf(\"Lowercase:\ \");
    //loop to convert the string to lowercase
    for (i = 0; i < sizeof(s); i++)
    {
        s[i]=tolower(s[i]);
    }
    printf(\"%s\", s);
 return 0;
 }
-------------------------output---------------
 Enter the string:   
 abcd1234ABCD
 Uppercase:
 ABCD1234ABCD
 Lowercase:
 abcd1234abcd
----------output ends---------------
Note: Feel free to ask doubts/queries. God bless you!!
![INTRO TO C Write a program that inputs a line of text with the function fgets() into char array s[100]. Output the line in both uppercase and lowercase letters. INTRO TO C Write a program that inputs a line of text with the function fgets() into char array s[100]. Output the line in both uppercase and lowercase letters.](/WebImages/40/intro-to-c-write-a-program-that-inputs-a-line-of-text-with-t-1122521-1761597697-0.webp)
