4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Number of elements in an array?
[Re: NITRO777]
#328631
06/14/10 12:31
06/14/10 12:31
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
it depends on the format, are they comma seperated, are they all written as one long string, are they all written underneath each other? maybe if you can show a piece of that, we can come up with something for you easier regards,
|
|
|
Re: Number of elements in an array?
[Re: NITRO777]
#328682
06/14/10 16:04
06/14/10 16:04
|
Joined: Mar 2009
Posts: 88
Walori
Junior Member
|
Junior Member
Joined: Mar 2009
Posts: 88
|
there would be another way also, incase none of the numbers is 0 exactly. Just put a file_var_read to the while loop and increase counter amount on each loop call. When 0 is reached close the loop.something like this:
var var_to_read = 0;
var var_amount = 0;
var handle_of_file = file_open_read("FILE.txt");
while(1)
{
var_to_read = file_var_read(handle_of_file);
if(var_to_read == 0)
{
break;
}
var_amount++;
}
Last edited by Walori; 06/14/10 16:05. Reason: code brackets!
|
|
|
Re: Number of elements in an array?
[Re: NITRO777]
#328731
06/14/10 22:01
06/14/10 22:01
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Untested auto enf-of-file checking
var var_to_read = 0;
var var_counter = 0;
var handle_of_file = file_open_read("FILE.txt");
...
while(1)
{
var_to_read = file_var_read(handle_of_file);
if(file_seek(handle_of_file,0,4) >= (file_length(handle_of_file)-0))
{
break;
}
var_counter++;
}
Because untested, the IF may need to check against (file_length(handle_of_file)-1)or (file_length(handle_of_file)-2) or even -3, depending if file ends with a line-feed or not. let us know how it goes...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Number of elements in an array?
[Re: EvilSOB]
#328732
06/14/10 22:07
06/14/10 22:07
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Also, seeing as you know the number-range, you could put the last number WELL outside the possible range, to act as an end-of-numbers marker. eg (untested again)
#define EOF -999999 //end-of-file value
var var_to_read = 0;
var var_counter = 0;
var handle_of_file = file_open_read("FILE.txt");
...
while(1)
{
var_to_read = file_var_read(handle_of_file);
if(var_to_read == EOF ) { break; }
var_counter++;
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|