This blog is under construction

Monday 24 June 2013

C program to convert uppercase to lowercase and vice versa

Write a C program to convert uppercase to lowercase and vice-versa.


  #include<stdio.h>
  int main() {
        char str[100];
        int i = 0;

        /* get the input from the user */
        printf("Enter your input:");
        fgets(str, 100, stdin);

        while (str[i] != '\n') {
                /* convert upper case to lower case */
                if (str[i] >= 65 && str[i] <= 90)
                        str[i] = str[i] + 32;

                /* convert lowercase to upper case */
                else if (str[i] >= 97 && str[i] <= 122)
                        str[i] = str[i] - 32;

                i++;
        }
        printf("Result: %s", str);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input:see-programming.blogspot.com
  Result: SEE-PROGRAMMING.BLOGSPOT.COM



No comments:

Post a Comment