Monday 8 December 2014

C program to convert a string into Upper Case

program to print upper case letters of given string
#include<stdio.h>
main()
{
char str[100],n,i;
printf("enter a string\n");
scanf("%[^\n]s",str);
printf("entered string is %s\n",str);
for(i=0;str[i];i++)
{
if((str[i]>='A')&&(str[i]<='Z'))
{
str[i]+=32;
printf("lower case is %c\n",str[i]);
}
else if((str[i]>='a')&&(str[i]<='z'))
{
str[i]-=32;
printf("upper case alphabet is %c\n",str[i]);
}
else
printf("entered character is not an alphabet\n");
}
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ cc array16.c
madan@madan-Lenovo-G570:~/madan$ ./a.out
enter a string
welcome
entered string is welcome
upper case alphabet is W
upper case alphabet is E
upper case alphabet is L
upper case alphabet is C
upper case alphabet is O
upper case alphabet is M
upper case alphabet is E