[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Question on ? "$" :

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Question on ? "$" :

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Azrith   (15 posts)  [Biography] bio
Date Tue 04 Feb 2003 10:30 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Azrith   (15 posts)  [Biography] bio
Date Reply #1 on Wed 05 Feb 2003 01:24 AM (UTC)  quote  ]
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!
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Wed 05 Feb 2003 06:56 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Dave   Australia  (93 posts)  [Biography] bio
Date Reply #3 on Fri 07 Feb 2003 10:11 PM (UTC)  quote  ]

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
[Go to top] top

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

Thanks again!
[Go to top] 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.


2,205 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]