If... then

Discuss PocketC for CE (including Desktop Edition)

Postby Tjadmaen on Mon Aug 18, 2003 7:38 pm

Hi all. I am sorry if the question sounds dumb to you, but I still can't get into the basics of pocketc. Here's the problem...
How can I make such thing working:

//must quit if pressed 'q' for example, when prompted
main()
{
char ch;
ch = getc();
if (ch = 'q')
quit();
else alert("bla bla");
}

but it quits always I press ANY button...
Please help! I can't overcome this simple start
Tjadmaen
 
Posts: 2
Joined: Mon Aug 18, 2003 7:13 pm

Postby Brendan Donovan on Tue Aug 19, 2003 8:54 am

In your if statement, you need to use a double ='s sign.

if(ch=='q')

One = sign is an assignment (hence your statement was always true)
Two == signs is a comparison

Hope this helps,
Brendan
Brendan Donovan
 
Posts: 3
Joined: Mon Aug 18, 2003 3:48 pm

Postby Tjadmaen on Tue Aug 19, 2003 7:48 pm

yes, that's it!
Thanks, Brendan!
Tjadmaen
 
Posts: 2
Joined: Mon Aug 18, 2003 7:13 pm


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 1 guest

cron