(Searching for Characters) Write a program that inputs several lines of text and a search character and uses function strchr to determine the total number of occurrences of the character in the lines of text.

What will be an ideal response?


```
#include
#include
#include
using namespace std;

const int SIZE = 80;

int main()
{
char text[ 3 ][ SIZE ];
char search;
char *searchPtr;
int count = 0;
int i;

cout << "Enter three lines of text:\n";

for ( i = 0; i <= 2; i++ )
cin.getline( &text[ i ][ 0 ], SIZE );

// make all characters lowercase
for ( i = 0; i <= 2; i++ )

for ( int j = 0; text[ i ][ j ] != '\0'; j++ )
{
char c = static_cast< char >( tolower( text[ i ][ j ] ) );
text[ i ][ j ] = c;
} // end for

cout << "\nEnter a search character: ";
cin >> search;

for ( i = 0; i <= 2; i++ )
{
searchPtr = &text[ i ][ 0 ];

while ( searchPtr = strchr( searchPtr, search ) )
{
++count;
++searchPtr;
} // end while
} // end for

cout << "\nThe total number of occurrences of \'" << search
<< "\' in the text is: " << count << endl;

return 0;
} // end main
```
Enter three lines of text:
The first line of text
The second line of text
The third line of text
Enter a search character: e
The total number of occurrences of 'e' in the text is: 10

Computer Science & Information Technology

You might also like to view...

Is an exception an object? Explain.

What will be an ideal response?

Computer Science & Information Technology

________ in Excel appear on the screen and by default do not display on printouts

Fill in the blank(s) with correct word

Computer Science & Information Technology

Consider a brokerage ?rm database with relations Holdings(AccountId, StockSymbol, CurrentPrice, Quantity) and Balance(AccountId, Balance). Write the triggers for maintaining the correctness of the account balance when stock is bought (a tuple is added to Holdings or Quantity is incremented), sold (a tuple is deleted from Holdings or Quantity is decremented), or a price change occurs. Solve the

problem using both row-level and statement-level triggers. Give an example of a situation when row-level triggers are more appropriate for the above problem and when statement-level triggers are more appropriate. What will be an ideal response?

Computer Science & Information Technology

A ________ is a context sensitive list of commands and options relevant to the active object

A) shortcut menu B) dialog box C) path D) pane

Computer Science & Information Technology