Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to convert upper case input characters to lower case or lower case input characters to upper case in C

1 Answer

0 votes
#include <stdio.h> 

void lower_to_upper();
void upper_to_lower();

int main(void)
{   
    int n;
    printf("Enter (1) for upper to lower\n");
    printf("Enter (2) for lower to upper\n");
    printf("1 OR 2:  ");
    scanf("%d",&n);
    switch (n)
    {
        case 1:
		{
            printf("Enter a string in upper case (Enter + Ctrl-C to exit): ");
            upper_to_lower();
            break;
		}
        case 2:
		{
            printf("Enter a string in lower case (Enter + Ctrl-C to exit): ");
            lower_to_upper();
            break;
		}
        default:
            printf("Error: Enter 1 Or 2");
    }
    return 0;
}
void upper_to_lower()
{
    char s[100], ch;
  
    for (int i = 0; (ch=getchar())!=EOF; i++)
        s[i]=(ch>='A' && ch<='Z')?('a' + ch -'A'):ch;
  
    printf("The lower case is: ");
    puts(s);
}

void lower_to_upper()
{
    char s[100], ch;
    
    for (int i = 0; (ch=getchar())!=EOF; i++)
        s[i]=(ch>='a' && ch<='z')?('A' + ch -'a'):ch;
  
    printf("The upper case is: ");
    puts(s);
}


 
/*
run:
   
Enter (1) for upper to lower
Enter (2) for lower to upper
1 OR 2:  1
Enter a string in upper case (Enter + Ctrl-C to exit): ABC
The lower case is:
abc

*/

/*
run:

Enter (1) for upper to lower
Enter (2) for lower to upper
1 OR 2:  2
Enter a string in lower case (Enter + Ctrl-C to exit): abc
The upper case is:
ABC

*/





 



answered Nov 2, 2016 by avibootz
...