0

How would you put a counter into an If statement to check if there is a specific amount of chars, Say 'x' or 'y'?

Thanks

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by DemonGal711
0

How would you put a counter into an If statement to check if there is a specific amount of chars, Say 'x' or 'y'?

Thanks

Too vague. Specific number of chars in what? Some string? What are x and y?

0

VernonDozier is right, but if I understand you correctly, putting a counter into an if statement wouldn't be of any help.

The if statement would go in, increment/decrement, and then go out. You'd need a loop either in or outside of the loop the if statement as well if you want to count, say the number of 'x' in the line "xxxxxxxxxxxxxxxxxxxxxx". Of course, you'd have to parse that line into the individual chars first, but that doesn't matter at the moment. The code would still be something like...

// parse string into characters
while ( /* not through all characters*/ )
        { if ( /* is this an x? */ )
              { xcount++; }
         }

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.