Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Azrith
(15 posts) 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
| top |
|
| Posted by |
Azrith
(15 posts) 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! | top |
|
| Posted by |
Nick Gammon
Australia (18,770 posts) 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 | top |
|
| Posted by |
Dave
Australia (93 posts) 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 | top |
|
| Posted by |
Azrith
(15 posts) 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! | 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,207 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )