while ..until

how do u say this :

decrement the pointer chr untill you find chr == ' ' OR chr == '<'

do
{
chr--; // or *chr-- whatever is reqd.
} while(chr != ' ' && chr !='<');

Sorry,

but he said chr== ' ' OR chr == '<'. And you say && which means AND, therefore you will never find a char which is both: ' ' AND '<'.

I think you have to use || which means OR instead of && (= AND)!

Also if you use "do { .. } while(..)" , the pointer gets decremented and afterwards compared to the while statement. Therefore you loose the first character.

Better use:

while(chr != ' ' || chr !='<') {
chr--; // or *chr-- whatever is reqd.
}

Here the value of the pointer gets compared first and then decremented!

hope I am right,

have fun
darkspace

You will stay in that loop while:
chr is not a space OR
chr is not a less than sign

One of those will always be true. So you have an infinite loop, now.

The original answer was better, but both seem to be using chr as both a pointer to character and as a character.

I don't like the do/until concept, but that is what the OP requested. For some reason, he is sure that the loop must be executed at least once.

And also, when scanning a string, you really need to check for the end of the string. I know that the OP didn't request this, but I can't help myself on this one.

So my answer:

do {
    chr--;
} while (*chr && *chr != ' ' && *chr != '<');

Totally I agree with Perderabo's opion.

But if the original value of chr is pointing to ' ' or '<', then
his answer will loss it because he uses do...while structure.

I think while structure is better.

This is my answer:
while ( *chr && *chr != ' ' && *char != '<'){
chr--;
}

I hope it be right.