May 2012
Intermediate to advanced
679 pages
16h 56m
English
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.
// 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 ...
Read now
Unlock full access