On 10/31/07, nimak247 <[EMAIL PROTECTED]> wrote:

> Hello all, I am brand-spanking new to C++, but love it already (At
> work I sorta picked up vba, and I had a lot of fun with it and wanted
> to try a real language just to increase my understanding of
> programming, so here I am)! I do have a question on something so basic
> I feel that even I should be able to figure it out (but can't). I am
> attempting to take a string and convert the whole thing into upper
> case, for which I have written the following lines:
>
> while (*str++)
>    *str = toupper(*str)
>
> ..which I thought meant: make char at first address uppercase, then
> move to the next address; continue until null is reached. But, when I
> run the code, it converts all the elements but the very first one. I
> must be misunderstanding something here, but I am not sure what. Can
> anyone lend a hand here? "str" in this case is the name of the char
> array, so I thought it would return the address of the first element
> in the array...

Because the loop skips over the first character on the first iteration
(you increment the pointer then do the operation). You need to do the
operation and then increment, like with a do ... while loop

do {

   ...

} while(*str++);

You could also use a for loop as well.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to