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

Write a function flipSwitches that accepts one argument, a sequence of upper or lower case letters...
Write a function flipSwitches that accepts one argument, a sequence of upper or lower case letters (the sequence can either be a str or a list, if you write your code correctly, it shouldn’t matter). This is a sequence of switches, uppercase means to turn a switch on, and lowercase to turn a switch off.   For example, ‘A’ means to turn the switch ‘A’ on, and ‘a’ means to turn the switch ‘A’ off.   (Turning an on switch on again,...
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 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.
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++
Write a value returning function named CountLower that counts the number of lower case letters on...
Write a value returning function named CountLower that counts the number of lower case letters on one line of standard input and returns that number. Document the dataflow of the function and show how it would be called from main().
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT