String char-case change in C.

01 #include<stdio.h>
02 #include<string.h>
03
04 /*
05 65-90 => ASCII 'A' to 'Z'
06 97-122 => ASCII 'a' to 'z'
07
08 32 => Difference between lower case and upper case letter.
09
10 'a' >> 97
11 'A' >> 65
12 ----------
13 32
14
15 */
16
17
18
19 void interchange(char[]);
20
21 int main()
22 {
23 char str[50];
24 printf("Enter any String : ");
25 gets(str);
26
27 printf("nBefore Interchange : %s",str);
28 interchange(str);
29 printf("nAfter Interchange : %s",str);
30
31 return 0;
32 }
33
34 void interchange(char str[])
35 {
36 int str_len=strlen(str);
37 int temp,i;
38 for(i=0; i<str_len; i++)
39 {
40 temp=(int)str[i];
41 if(temp>=65&&temp<=90)
42 {
43 str[i]=(char)temp+32;
44 }
45 else if(temp>=97&&temp<=122)
46 {
47 str[i]=(char)temp-32;
48 }
49 }
50 }
 
 OUTPUT :

Enter any String : ThIs iS a dEMo !!!

Before Interchange : ThIs iS a dEMo !!!
After Interchange : tHiS Is A DemO !!!

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.