Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Program to Convert String into Uppercase

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 619
    Comment on it

    Using library function:

    We can use toupper() library function present in "string.h" to convert string into uppercase.

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
       char str[100];
    
       printf("Enter a string to convert it to Uppercase\n");
       gets(str);
    
       printf("Input string in upper case: %s", toupper(str));
    
       getch();
    }
    

    Without using Library Function:

    In this program we are using a function upper() which will take a string as argument and convert into uppercase character by character and will return that character.

      #include <stdio.h>;
    
    char upper(char char1)
    {
          char char2;
    
          if(char1 >= 'a' && char1 <= 'z'){
                char2 = ('A' + char1 - 'a'); // converting into uppercase
                return char2;                // returning uppercase character
          }
          else{                               //character are already in uppercase
                char2 = char1; 
                return char2;
          }
    }
    
    int main()
    {
          char lowercase, uppercase;
    
          printf("Enter a string to convert it to Uppercase\n");
          scanf("%c", &lowercase);
    
          uppercase = upper(lowercase);
    
          printf("The string in  uppercase  is: %c", uppercase);
          return 0;
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: