answersLogoWhite

0

Since this question appears in both the C and Java sections, I'll give you the (slightly different) answers for each.

In Java

final String str; // the string we want to search

final char c; // the character we want to search for

int num = 0; // the number of times c is in str

for(char ch: str.toCharArray()) {

if( ch == c ) {

++num;

}

}

// num now equals number of times c is in str

In C

const char* str; // the string we want to search

const char c; // the character we want to search for

int num = 0; // the number of times c is in str

// loop vars

int i;

const int end = strlen(str);

for(i = 0; i < end; ++i) {

if( str[i] == c ) {

++num;

}

}

// num now equals the number of times c is in str

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

A computer programmer wrote a program that adds two numbers The programmer ran the program and observed that when 5 is added to 8 the result is the character m Explain why this program is behaving?

This is happening because when the programmer is displaying the number, it is being displayed as a character with a decoding process of a = 1, b = 2, etc. 5 + 8 = 13 = m


How do you write assembly language program for displaying a character in 8x8 LED matrix using 8088 microprocessor kit?

To write an assembly language program for displaying a character on an 8x8 LED matrix using the 8088 microprocessor kit, you first need to define the bit pattern for the character in the program. Then, set up the appropriate I/O ports for the matrix, ensuring you understand the pin configuration for rows and columns. The program will typically involve initializing the matrix, sending the bit pattern to the corresponding rows and columns, and implementing a loop to continuously refresh the display. Use instructions like OUT to send data to the ports and DELAY for timing control to ensure the display is stable.


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


What is a filtering program that stops pop ups from displaying on webpages?

Pop-up blocker


Can you cheat at Yahoo spades?

Yes!!!! Cheat with partner or get card counting program! You can get the card counter program at http://www.beatmygame.com/yahoospadescounter.html


Program Manager should notify the Milestone Decision Authority within 90 days of the occurrence?

false


What show does Teto and Miku come from?

The character Teto comes from the program known as UTAU. The character Miku comes from the program known as Vocaloid.


5: No Calorieor Point Counting?

The Eastside Weight Loss Clinic program teaches you how to eat real food without counting calories or points. This can make the program more manageable and sustainable in the long term, as it does not require you to constantly track and monitor your food intake.


What kind of character is Bubbles on an HBO program?

Bubbles is a prevalent character in the HBO program The Wire. His character is a recovering Heroin addict. His real name is actually Reginald Cousins and has a son that lives with his mother.


Write a program to enter a character and it will tell the character etered?

{char a;...cout > a;cout


Which cartoon character is the face of the Middle School FFA program at the National FFA?

Garfield is the character


How is memory allocated in c program for a character data type?

One byte for every character.