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 ➜ Simple Function to input from a file.

Simple Function to input from a file.

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


Posted by Azrith   (15 posts)  Bio
Date Fri 21 Feb 2003 02:45 AM (UTC)
Message
Hey everyone. Im back! hehe I am trying to set up a simple array (or not so simple for me apparantly). I want to input a bunch of 0s and 1s from a text file into this integer array. I also only want it to input 1 integer at a time.
For some reason I am having trouble. The main input loop is
for (dumcount = 0 ;dumcount < 200 && (!feof(fpList)) ; dumcount++ )
{
dummynum = fgetc(fpList);
vnum_ship_list[dumcount] = dummynum;
}
I believe the problem lies with the EOF but I can't seem to figure out what it is.
Any help would be greatly appreciated!
Thanks!
Top

Posted by Nick Gammon   Australia  (23,162 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 21 Feb 2003 09:28 PM (UTC)

Amended on Fri 21 Feb 2003 09:29 PM (UTC) by Nick Gammon

Message
In what way does it not work? For a start, you said an "integer array" however you will be reading in "0" or "1" not 0 or 1.

In other words, "0" will be 48 decimal (0x30 in hex), and "1" will be 49 decimal (0x31 in hex), so in neither case will you get a real zero into the array.

One variation would be to change the line:


vnum_ship_list[dumcount] = dummynum;	


to read:


if (dummynum == "1")
  vnum_ship_list[dumcount] = 1;
else
  vnum_ship_list[dumcount] = 0;


- Nick Gammon

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

Posted by Azrith   (15 posts)  Bio
Date Reply #2 on Sat 22 Feb 2003 02:29 AM (UTC)
Message
Ahh I see what you're saying about the input. I thought fgetc performed differently but I believe my real problem is the EOF flag in my for loop. I initially set up this array to be all 0s. Then I call this load function. For some reason even if I have a blank file it still goes into this for loop. I can't seem to figure out why it is entering the for loop when the file is blank.:) Thanks for the help!
Top

Posted by Azrith   (15 posts)  Bio
Date Reply #3 on Sat 22 Feb 2003 02:36 AM (UTC)
Message
Wow very interesting. After I changed the code you had told me it appears to be working fine now. I am working on revamping smaug 1.4 to a new scifi mud. :) In the middle of creating ships. I didn't like the way star wars was using them so I figured Id start fresh hehe.
Thanks for the quick help Nick!
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.


12,673 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.