Also, the declaration
    char TempCode[4] = "0000\0";
doesn't look right.  I'm not sure if the compiler will recognize \0 inside
of quotes as a null terminator or treat it as two chars, but in any case 4
is not big enough to hold TempCode.  When you assign a string inside of full
quotes, the compiler (CodeWarrior is all I'm familiar with) automatically
appends the null terminator to the string.

So, for example,
    Char Temp[4] = "abc";
allocates 4 bytes, points Temp to that space, and puts 'a', 'b', 'c', '\0'
there.

And
    char TempCode[4] = "0000\0";
allocates 4 bytes, points TempCode to those bytes, then tries to store '0',
'0', '0', '0', '\', '0', '\0' there.  I'd be very surprised if this doesn't
cause something else to be over-written.  Or, maybe it just stores the first
4 bytes.   Then you'd have a non-null-terminated string which would cause
other problems.

----- Original Message -----
From: "Stuart Nicholson" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Wednesday, July 12, 2000 11:53 AM
Subject: RE: Newbie to Palm question about using variable


> I think you'll find the last if statement is changing the address of the
> TempCode string (strings are just addresses in C) to point to the static
> "0000\0" string you define. Once you've done this the first time I think
> you'll find you can't change the string contents any more (actually I'm
> surprised the Palm Emulator doesn't complain when you try to).
>
> I'd say instead of this:
>
> if( // the '#' button is pressed )
> {
>     *TempCode = "0000\0";
>     CurChar = 0;
> }
>
> You should do something like this:
>
> if( // the '#' button is pressed )
> {
>     StrCopy( TempCode, "0000\0" );
>     CurChar = 0;
> }
>
> But then I could be wrong ;) hope that helps!
>
> Stuart Nicholson
> Programmer
> Firepad, Inc.
>
> -----Original Message-----
> From: Patrick Ouellet [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 12, 2000 5:48 PM
> To: Palm Developer Forum
> Subject: Newbie to Palm question about using variable
>
>
> Ok I tried something really easy.
>
> // Regular C of what I want to do.
>
> char TempCode[4] = "0000\0";
> int CurChar = 0;
>
> if( // the button #2 is pressed )
> {
>     TempCode[CurChar] = '2';
>     CurChar++;
> }
>
> if( file://the button #3 is pressed )
> {
>     TempCode[CurChar] = '3';
>     CurChar++;
> }
>
> if( // the '#' button is pressed )
> {
>     *TempCode = "0000\0";
>     CurChar = 0;
> }
>
> But no matter what I do TempCode never change.
>
> Is there something I don't know I really should
> Or am I just a id10t
>
> --
> Patrick Ouellet, Programmeur/Analyste
> Département: Recherche & Développement
> Les Entreprises Microtec Inc.
> 4780 rue St-Félix, St-Augustin, Qc, G3A-2J9
> (418) 864-7644 poste 130
> [EMAIL PROTECTED]
> http://www.microtecsecurite.com/
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/tech/support/forums/
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
>


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to