Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > C question again

C question again
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2002
Status: Offline
Reply With Quote
Nov 27, 2002, 09:25 PM
 
What does this while loop test for?

char str[80], *p;
p=str;

while(*p) {
blah blah blah…
}

I know its tests to see if *p is true, but how does *p become true?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 27, 2002, 09:59 PM
 
When p doesn't point to the value '\0'.

Remember: As far as control statements are concerned, 0 is always false, anything else is true.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Nov 29, 2002, 01:20 PM
 
I guess in "blah blah blah" it increments p, so it loops down the string character by character until the end, when p points to the last byte in the string. The last byte of a cstring is always 0, and the while loop terminates.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2