UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to convert the first letter of each word to uppercase

C program for how to convert first letter of each word to upper case

by Krishna viswambharan


Posted on 10 Oct 2017 Category: C Views: 2411

Edited on 09 Feb 2018


C program to convert the first letter of each word to uppercase

In this C program we will learn how to capitalize the first letter of each word to uppercase.  For this conversion C library function ‘toupper’ can be used. 

Source code for the conversion is given as below:-

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
     char name[50];
     int i=0;
     printf(“Enter the string :”);
     gets(name);
     name[0]=toupper(name[0]);
     while(name[i]!=’\0’)
     {
	       if(name[i]== ‘ ‘)
		       name[i+1]=toupper(name[i+1]);
	       i=i+1;
     }
     puts(name);
     getch();
}

output



Leave a Comment:

                                                    

alisha Saturday,16 Jun 2018

what is the use of putting i+=1 at the end of while loop as till we don't get null character , loop will always run. so if wwe don't put this statement prgram will run.

Advertisement