Saturday, July 7, 2012

String Title case

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****************/

Output of C program of string title case
Screen shot of title case C program


Related programs:

  1. Reverse all string
  2. Reverse all words but not string
  3. Reverse each first character of word & add extra word
  4. Display string vertically
  5. Search sub-string from main string
  6. Search sub-string individual from main string
  7. Position and repetition of character in string

No comments:

Post a Comment