Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Question on ? "$" :

Question on ? "$" :

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Azrith   (15 posts)  Bio
Date Tue 04 Feb 2003 10:30 PM (UTC)
Message
Hey everyone!
I was wondering if someone could give me a little more info as to what exactly the ? "$": does in the line
filename = feof( fpList ) ? "$" : fread_word( fpList );

This line is with
filename = feof( fpList ) ? "$" : fread_word( fpList );
if ( filename[0] == '$' )
break;

Thanks!

Kyle
Top

Posted by Azrith   (15 posts)  Bio
Date Reply #1 on Wed 05 Feb 2003 01:24 AM (UTC)
Message
PS :)

I realize the "$" is the end of file so is it saying if $ is found then filename = EOF otherwise filename = fread_word?

Thanks!
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Wed 05 Feb 2003 06:56 AM (UTC)
Message
What they are saying is that a file *should* end with "$" but if it doesn't, in other words, if feof is true, then simulate that by putting a "$" into filename, otherwise read a filename from the file.

Then the subsequent test just tests for a "$" and doesn't have to test for end-of-file as well.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dave   Australia  (93 posts)  Bio
Date Reply #3 on Fri 07 Feb 2003 10:11 PM (UTC)

Amended on Fri 07 Feb 2003 10:13 PM (UTC) by Dave

Message
The ? and : thing is called the ternary operator, and it's a short-hand form of a simple if-then-else. For example:
filename = feof(fpList) ? "$" : fread_word(fpList);
Could be written as:
if (feof(fpList))
    filename = "$";
else
    filename = fread_word(fpList);
Like many things in C, the ternary operator can be abused. I've seen massively-nested ?:'s which, while amusing, were certainly unreadable. For more information, google for "ternary operator".

Hope this helps,

Dave
Top

Posted by Azrith   (15 posts)  Bio
Date Reply #4 on Sun 09 Feb 2003 01:49 AM (UTC)
Message
Thanks for all the help everyone :)
Ya I remember going over this a long time ago I had just forgotten.

Thanks again!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,166 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.