Write a program to convert the string from lower case to upper case


Default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Write a program to convert the string from lower case to upper case
// Ex: lower->LOWER;

 
#include<stdio.h>
#include<string.h>
int main(){
    char str[100],str1[100],str2[100];
    printf("Enter any string:");
    scanf("%s",str);
    int i;
    printf("Converting to upper case\n");
    for(i=0;i<=strlen(str);i++){ if(str[i]>=97&&str[i]<=122){
              str1[i] = str[i]-32;                      
         }  
         else{
              str1[i] = str[i];
         }
    }
    printf("Using method1: %s\n",str1);
    for(i=0;i<=strlen(str);i++){
         if(islower(str[i])){
              str2[i] = str[i]-32;              
         }      
         else{
              str2[i] = str[i];
         }                
    }
printf("Using method2: %s\n",str2);
    getch();
}

No comments:

Post a Comment