answersLogoWhite

0


Best Answer

There are many ways to achieve this. Example:

#include <iostream>

using namespace std;

int main()

{

char str[256];

memset( &str, 0, 256 );

cout << "Enter a string with some spaces: ";

cin.getline( str, 256, '\n' );

int count = 0;

char * p = str;

while( p < str + 255 )

{

if( *p == 32 ) ++count;

++p;

}

cout << """ << str << "" has " << count << " spaces!" << endl;

return( 0 );

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is c program to count number of blank spaces in string?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write c program to accept a string from the console and count number of vowels constants digits tabs and blank spaces in a string?

Read the characters one at a time, and write an "if" for each of the cases. In each case, if the condition is fulfilled, increment the corresponding counter variable.


String functions Of sql server 2005?

SQL Server provides us with a variety of string functions. Some of them are:LOWER - To convert a string to lower caseUPPER - To convert a string to upper caseLTRIM - To trim blank spaces from the left side of the stringRTRIM - To trim blank spaces from the right side of the stringSUBSTRING - To pick up specific portions of a stringREVERSE - To reverse the input stringREPLACE - To replace the character at a specified position of a string with anotheretc.


How do you get your name to be undefined on poptropica?

There is no way. You need a username and password to play, and the program will not accept all blank spaces or dashes.


Number line for 2493 3 spaces then 8008?

waht gose and the blank 2493_ _ _ _ 8008


What are the release dates for Blank Spaces - 2010?

Blank Spaces - 2010 was released on: USA: 22 February 2010 (internet)


In a java program in a return statement with string concatenation how do you print a blank line?

use "\n" between the words where you want a new line


How many blank spaces were in mendeleeves periodic table?

There were 3 blank spaces in mendeleev's Periodic Table. He left it for the elements which were not discovered at that time.


Es-pin mind quiz code blank with spaces?

Paper with spaces


Blank program?

_______ program


Will blank spaces be accepted in getchar?

yes


How did mendeleev explain blank spaces left in his periodic table?

On his Periodic Table Mendeleev left the blank spaces, because he thought there would be elements that would follow his pattern.


Write a program that in c plus plus will parse a text file exampletxt and printout number of words in file number of characters number of blank spaces?

#include&lt;iostream&gt; #include&lt;fstream&gt; int main() { std::ifstream infile ("example.txt", std::ios::in); unsigned chars(0); unsigned words(0); unsigned spaces(0); std::string delim("\t\n "); char ch(0); char last(0); if (!infile.good()) { std::cerr &lt;&lt; "The filename is invalid." &lt;&lt; std::endl; return -1; } while (infile.get(ch)) { switch (ch) { case (' '): case ('\t'): ++spaces; case ('\n'): // only count words if the last char was not a word delimiter if (delim.find(last) == std::string::npos) ++words; default: ++chars; } last = ch; } infile.close(); std::cout &lt;&lt; "Number of chars:\t" &lt;&lt; chars &lt;&lt; std::endl; std::cout &lt;&lt; "Number of words:\t" &lt;&lt; words &lt;&lt; std::endl; std::cout &lt;&lt; "Number of spaces:\t" &lt;&lt; spaces &lt;&lt; std::endl; }