Question

In: Computer Science

In a c programming Write a program that converts upper case letters to lower case letters...

In a c programming

Write a program that converts upper case letters to lower case letters or vice versa:

Enter a sentence: What a GREAT movie is!

Converted sentence: wHAT_A_great_MOVIE_IS_

Convert all non-alphabetical letters to ‘_’

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

code.c

#include <stdio.h>

void convertCase(char * line){
   int i=0;
   char c;
   while (line[i] != '\0')
   {
       //get the char
       c = line[i];
       //convert to ascii
       int ascii = c;
       //if 97 to 122 is lowercase range
       //convert to ascii back to char
       char converted ;
       if(ascii>=97 && ascii<=122 ){
           //difference between uppercase and lower case is 32. if we deduct 32 from lower case it will convert to uppercase
           ascii-=32;
           //range 65 to 90 is uppercase range
           converted = ascii;
       }else if(ascii>=65 && ascii<=90){
           //if we will add 32 to upper case it will convert to lower case
           ascii+=32;
           converted = ascii;
       }else{
           converted = '_';
       }

       line[i] = converted;
       i=i+1;
   }
}
int main()
{
   char line[100];
   printf("Enter a sentence: ");
   gets(line);
   convertCase(line);
   printf("Converted sentence: %s",line);
   return 0;
}


Related Solutions

Assembly code Write an assembly program that converts all uppercase letters to their corresponding lower cases....
Assembly code Write an assembly program that converts all uppercase letters to their corresponding lower cases. meanwhile all characters that are not upper case letters should remain unchanged. Hint: ASCII: a = 97, z = 122, A = 65, Z = 90 String : "Riders On The Storm - The Doors"
Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
Write a C++ program that converts an infix expression, which includes (, ), +, -, *,...
Write a C++ program that converts an infix expression, which includes (, ), +, -, *, and / operations to postfix notation. The program should allow the user to enter an infix expression using lower case characters, then it will display the result of conversion on the screen. (Note: Use the STL stack class to accomplish the solution.).
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts...
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts a Celsius temperature to Fahrenheit. Modify that program so it uses a loop to display a table of the Celsius temperatures 0–20, and their Fahrenheit equivalents. Display table on screen and it a .txt file. c++
In python idle 3.9.0 write a function that: i) will count all lower case, upper case,...
In python idle 3.9.0 write a function that: i) will count all lower case, upper case, integers, and special symbols from a given string. The input string is provided by the user. ii) will check if a sting is a palindrome. User supplies the input string.
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
2. Write a C++ program that; Takes in the weight of a person in Kilograms, converts...
2. Write a C++ program that; Takes in the weight of a person in Kilograms, converts and outputs the equivalent weight in pounds. Format your output to 3 decimal places. Your output should look like this 53.000 Kg is equivalent to 123.459 Ibs (Note 1Kg = 2.2046226218488 lbs) Takes in the price of an item on an online store in pound sterling, converts and outputs the equivalent price in U.S dollars. Format your output to 2 decimal places. Your output...
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
For a game that takes user input of certain letters, Upper: O,C,I,Z; Lower: o,c,i,z. The board...
For a game that takes user input of certain letters, Upper: O,C,I,Z; Lower: o,c,i,z. The board is a 4 by 4 matrix and the numbers on the right are the positon that correspond with the dots. So if player 2 statisfies the requirement for the winning condition. Winning conditions being 4 letters in a row of (all upper case-- Z I C O ), (all straight-line-- Z I i I), (all consonants - Z z C c), (all curved-- C...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT