Q. Write a C program to accept a string from user change it to title case i.e. first character of each word in string must be capital letter.
For example if string is: are you confident to write c programs?
Result: Are You Confident To Write C Program?
Ans.
/*c program for change case of string or title case of string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int tmp,i;
char str[30];
printf("Enter any string: ");
gets(str);
for(i=0; str[i]!='\0'; i++)
{
if(str[i-1]==' ' || i==0)
{
if(str[i]>='a' && str[i]<='z')
str[i]=str[i]-32;
else
if(str[i]>='A' && str[i]<='Z')
str[i]=str[i]+32;
}
printf("%c",str[i]);
}
getch();
return 0;
}
/****************Output****************/
Related programs:
For example if string is: are you confident to write c programs?
Result: Are You Confident To Write C Program?
Ans.
/*c program for change case of string or title case of string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int tmp,i;
char str[30];
printf("Enter any string: ");
gets(str);
for(i=0; str[i]!='\0'; i++)
{
if(str[i-1]==' ' || i==0)
{
if(str[i]>='a' && str[i]<='z')
str[i]=str[i]-32;
else
if(str[i]>='A' && str[i]<='Z')
str[i]=str[i]+32;
}
printf("%c",str[i]);
}
getch();
return 0;
}
/****************Output****************/
Screen shot of title case C program |
Related programs:
Comments
Post a Comment