Uppercase To Lowercase in C
#include<stdio.h>
#include<string.h>
int main()
{
char strr[20];
int i;
scanf("%s\n",strr );
for ( i = 0; i < strlen(strr); ++i)
{
if(strr[i]>=65 && strr[i]<=90){
strr[i]= strr[i]+32;
}
/* code */
}
printf(" %s",strr);
/* code */
return 0;
}
Algorithm:
ASCII value of 'A' is 65 while 'a' is 97. Difference between them is 97 – 65 = 32
In general rule:
Upper case character = Lower case character – 32
Lower case character = Upper case character + 32
#include<string.h>
int main()
{
char strr[20];
int i;
scanf("%s\n",strr );
for ( i = 0; i < strlen(strr); ++i)
{
if(strr[i]>=65 && strr[i]<=90){
strr[i]= strr[i]+32;
}
/* code */
}
printf(" %s",strr);
/* code */
return 0;
}
Algorithm:
ASCII value of 'A' is 65 while 'a' is 97. Difference between them is 97 – 65 = 32
In general rule:
Upper case character = Lower case character – 32
Lower case character = Upper case character + 32
- strlwr(string)
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment