little fileread problem

Posted By: malhal

little fileread problem - 07/10/09 13:54

File read

After working for three months with 3dGamestudio I finally managed to make a nice game, however I’m still have trouble with a few very basic routines such as reading numbers from a file and store them in an array.


When I run the following lines:



var fhandle;

STRING* test_str;

function main()
{
video_mode = 7;
screen_color.blue = 150;


fhandle = file_open_read("test.txt");
file_str_read(fhandle,test_str);
file_close(fhandle);
}

I get the error: “invalid pointer or handle in a function”. I didn’t come up with this code myself but got it from the help file, it does not work however. Is this C script instead of Lite C? If this is solved, the next step would be to put the numbers in an array. Who can help me with this little fileread problem?
Posted By: DJBMASTER

Re: little fileread problem - 07/10/09 14:26

You are mixing both languages together, that's not allowed.

Try this...

Code:
var fhandle;
STRING* test_str;

void main()
{
video_mode = 7; 
wait(1);
vec_set(screen_color,vector(150,0,0));
fhandle = file_open_read("test.txt"); 
file_str_read(fhandle,test_str); 
file_close(fhandle);
}


Posted By: malhal

Re: little fileread problem - 07/10/09 20:04

Thanks... but... using your code I get exactly the same error as before:
“invalid pointer or handle in a function”

could you give me a solution in Lite C?
Posted By: DJBMASTER

Re: little fileread problem - 07/10/09 20:13

That is lite-c. That error seems to indicate that the 'fhandle' variable is invalid and therefore i guess that the file isn't opened/read properly.

Try again with a new .txt file, and make sure it is in the same directoy as your script.
Posted By: Widi

Re: little fileread problem - 07/10/09 20:54

Do you include :

#include <acknex.h>

If not, set this Line at the top of your script. And make the lite-c Workshop...
Posted By: EvilSOB

Re: little fileread problem - 07/11/09 04:11

STRING* test_str = "";
Posted By: Widi

Re: little fileread problem - 07/11/09 16:32

@EvilSOB: oh yeah, you are right....
Posted By: EvilSOB

Re: little fileread problem - 07/11/09 17:54

You needed to tour an un-initialised string pointer
into an actual string that can be filled by file_str_read.
Easy mistake.
Posted By: malhal

Re: little fileread problem - 07/13/09 20:52

Ok thanks you all... it worked.

STRING* test_str = "";

is indeed necessary, but the error message I got: “invalid pointer or handle in a function” was about something else....

somehow I saved the file: test.txt as test.txt.txt, this kind of file name is allowed by Vista (strange??) but not by Lite c of course. To make simple things more complicated Vista explorer did doew not show the file extension, so I just saw test.txt, only when I made a second text file I saw my mistake.... I really feel like a beginner, thanks anyway.
© 2024 lite-C Forums