This blog is under construction

Monday 15 July 2013

C program to convert the string from uppercase to lowercase

Write a C program to convert uppercase string to lowercase.



  #include <stdio.h>
  #include <string.h>

  int main() {
        char string[256];
        int i = 0;

        /* get the input string from the user */
        printf("Enter your input string:");
        fgets(string, 256, stdin);
        string[strlen(string) - 1] = '\0';

        /* print the uppercase input string */
        printf("UpperCase: %s\n", string);
        while (string[i] != '\0') {

                /* convert uppercase string to lowercase */
                if (string[i] >= 'A' && string[i] <= 'Z') {
                        string[i] = (string[i] - 'A') + 'a';
                }

                i++;
        }

        /* print the lowercase input string */
        printf("LowerCase: %s\n", string);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input string:HAI.. HELLO!! HOW ARE YOU??
  UpperCase: HAI.. HELLO!! HOW ARE YOU??
  LowerCase: hai.. hello!! how are you??


No comments:

Post a Comment