Characters and Strings: Namiq Sultan
Characters and Strings: Namiq Sultan
Namiq Sultan
University of Duhok
Department of Electrical and Computer Engineerin
void main()
{
char input;
Function De scription
void main()
{
const float pi = 3.14159;
float radius;
char go;
Figure 10-1
void main()
{
char line[80];
int count = 0;
// Function prototype
int countChars(char *, char);
void main()
{
char userString[51], letter;
cout << "Enter a string (up to 50 characters): ";
cin.getline(userString, 51);
cout << "Enter a character and I will tell you how many\n";
cout << "times it appears in the string: ";
cin >> letter;
cout << letter << " appears ";
cout << countChars(userString, letter) << " times.\n";
}
C++ Programming, Namiq Sultan 19
// Definition of countChars. The parameter strPtr is a pointer
// that points to a string. The parameter ch is a character that
// the function searches for in the string. The function returns
// the number of times the character appears in the string.