C++ Program to Convert first alphabet of every word in a string from lowercase to uppercase

C++ Program to Convert first alphabet of every word in a string from lowercase to uppercase

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>

void main()
{
 clrscr();
 char a[50];
 int i;
 cout<<“Enter a string:”;
 gets(a);
 cout<<“n”;

 if(islower(a[0]))
 a[0]=toupper(a[0]);

 for(i=0;a[i]!=’’;++i)
 {
  if(a[i]==’ ‘)
   if(islower(a[i+1]))
   a[i+1]=toupper(a[i+1]);
 }

 cout<<“The new string is:”<<a;
 getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *