Strings: Declaring and Initializing String Variables
Strings: Declaring and Initializing String Variables
do
{
ch=getchar();
a[i]=ch;
i++;
}while(ch!='\n');
printf("%s",a);
}
3.program to print upper case to lower case and vice versa
void main()
{
char str[20];
printf("enter str");
scanf("%s",str);
int i;
for(i=0;i!='\0';i++)
{
if(str[i]>='A' && str[i]<='Z')
{
str[i]+=32;
}
else
{
str[i]-=32;
}
}
printf("%s",str);
}
4.program to print the length of the string
void main()
{
char str[30];
int i,c=0;
printf("enter str");
scanf("%s",str);
for(i=0;i<=30;i++)
{
if(str[i]!=0)
{
c++;
}
else
break;
}
printf("length=%d",c);
}