8.4.1 Capitalize first character

Problem: Write a program to read a sentence (string) into an array and capitalize the first character of every word in the input.

Solution: We have to identify the first character of every word. We are going to scan the array character by character. When we encounter a blank, it means we are going to get a fresh word. This information is stored in a variable flag. To get uppercase character we use function toupper(ch) defined in<ctype.h>. See Program 8.2.

Program 8.2 Capitalize first character

// cap1.cpp#include<stdio.h>#include<iostream.h>#include<string.h>#include<ctype.h>int main(){ int i ,flag ;  char s1[20], s2[20] ;  cout << “<---cap1.cpp--->” << endl ;  cout << “ give string ...

Get Object Oriented Programming with C++, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.