program to count the number of characters in any string excluding the blank space.

That's nice. Is there a question you'd like to ask now?

and your attempt is......

create a pointer and use increament operator to read the string. This should be maintained in a loop till the end of string. And for every next character make a check using if(*ptr == ' ') then your counter, which counts the number of words, should not increase.

This is pretty simple. Just take your string (which depending on how your using strings, will be a char* or an std::string), and iterate through each char until you reach the '\n' new line character.

What's going on here?..

replace (mystring.begin(), mystring.end(), " ", "");
cout << mystring.length() << endl;  // what?

i think you should use the strlen after you write the output code..
strlen is to count the number of characters..

>strlen is to count the number of characters..
...in a C-style string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.