i have to write a code that should count spaces. i am writting in this way but its not working.
if (input==' ')
space++;

Recommended Answers

The supplied piece of code isn't wrong. If it's not working it is something else within the program that is causing issues.

Jump to Post

All 3 Replies

The supplied piece of code isn't wrong. If it's not working it is something else within the program that is causing issues.

see below

What type of variable is input? Where are you getting the data from that you need to count spaces in?

if input is of type char, then you'd have:

if (input == ' ') // not ''
        space++;

if it's a std::string then:

    if (input == " ")
Be a part of the DaniWeb community

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