This blog is under construction

Monday 15 July 2013

C program to convert the string from lowercase to uppercase

Write a C program to convert lowercase string to uppercase.


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

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

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

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

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

                i++;
        }

        /* print the uppercase string */
        printf("UpperCase: %s\n", data);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input string:pursuit of happiness
  LowerCase: pursuit of happiness
  UpperCase: PURSUIT OF HAPPINESS


No comments:

Post a Comment