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 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.
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 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...
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...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the...
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the input via ignoring the case sensitivity. For example, sample outputs could be like below. Please input a string: This is a list of courses. CSC 1010 - COMPUTERS & APPLICATION Here is the letter frequency: Letter a or A appears 3 times Letter b or B appears 0 times Letter c or C appears 5 times Letter d or D appears 0 times Letter...
c++ programming: Write a function called baseConverter(string number, int startBase, int endBase) in c++ which converts...
c++ programming: Write a function called baseConverter(string number, int startBase, int endBase) in c++ which converts any base(startBase) to another (endBase) by first converting the start base to decimal then to the end base. Do not use library. (bases 1-36 only)
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT