Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (OptimusPrime, AndrewAMD), 14,580 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
is there a end of file function? #270784
06/09/09 22:12
06/09/09 22:12
Joined: Apr 2009
Posts: 18
F
FlyingRaven Offline OP
Newbie
FlyingRaven  Offline OP
Newbie
F

Joined: Apr 2009
Posts: 18
I need to check trough an entire file, now in c++ I know what to do and what to use. there I would use while(!feof(<filename>)).
and my question is does lite-c have a simular function?

Re: is there a end of file function? [Re: FlyingRaven] #270840
06/10/09 09:26
06/10/09 09:26
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
There is no separate function as such in lite-c to check for EOF.
The way to check for EOF all depends on HOW you are reading the file.
Are you readng strings, vars, or whatever.
Post you existing (even partial/non-functional) attempt at coding this.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: is there a end of file function? [Re: EvilSOB] #270865
06/10/09 10:46
06/10/09 10:46
Joined: Apr 2009
Posts: 18
F
FlyingRaven Offline OP
Newbie
FlyingRaven  Offline OP
Newbie
F

Joined: Apr 2009
Posts: 18
well right now I have an extreamly ugly 'hack' to do it.
I read in the max lines at the top of the txt file, the problem is that that means everytime you change the file you have to update this number and there is just a lot that can go wrong with this aproach.

so lets say this is the test file.

19 <--- maximum amount of lines
3 <--- where the questions start (it's to ensure the numbers aren't print)
3 <--- the amount of lines that need to be opened (to ensure it doesn't open more then it should)

so when the file is opened it opens this

test question 1 <----- sets the search string to this question (when selected)
test question 2 <----- sets the search string to this question (when selected)
exit <--- takes you out of the function (when selected)

when a question is found the
beginning of the lines to be coppyed to the screen and the amount are changed to the amounts needed fore the text box.

now in c++ I have a lot better way to do all this but here I just don't know how. and I know how ugly this is thats why I am requestion a better solution.

Code:
 

function getText()
{
	var filehandle;
	
	fileHandle = file_open_read("text/test.txt");
	
	var maxLines = 0;
	var lines = 0;
	var linesBegining = 0;
	
	maxLines = file_var_read(filehandle);
	lines = file_var_read(filehandle);
	linesBegining = file_var_read(filehandle);
	
	var k = 0;
	k = lines + linesBegining;
	
	//temp.z = 0;

	str_cpy(checkString, buffer.string[gid01_choise_value+linesBegining]);
	
	if (fileHandle)
	{
		temp.x = txt_load(buffer, "text/test.txt");
		temp.y = str_len(buffer.string[temp.x -1]);

		while(maxLines > k)
		{
			
			//str_cpy(text.string[k], buffer.string[k]);
			if(checkString == buffer.string[k])
			{
				lines = file_var_read(filehandle);
				linesBegining = file_var_read(filehandle);
				break;
			}
			k +=1;
		}	
		
		k = linesBegining;
		
		while(k < lines + linesBegining)
		{
			str_cpy(text.string[k], buffer.string[k]);
			k +=1;
		}
	}
	file_close(fileHandle);
}



I also have 2 questions.

1. the string to string comparison doesn't seam to work. not a big serprise really but if I could get some advice on this as well it would be aprisiated.

2. when I tried to replace the "text/test.txt" here <temp.x = txt_load(buffer, "text/test.txt");> with filehandel wich contains that text it gives an error I figured this was becouse it was a var and not a char or string but those also seam to give me trouble since they don't alow me to do this

stringFile = "text/test.txt";

so fore every file I now have to make a hand made option. this goes well fore now since I only have 1 file but soon I do not.

also thanks fore all the help in advanced I'm really not used to asking this much help but I'm new to lite-c and have a extreamly tight deadline.

Re: is there a end of file function? [Re: FlyingRaven] #270898
06/10/09 12:28
06/10/09 12:28
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Before I really read this post properly, I need more coffee,
BUT
Feel free to post the core of your C++ code so I can see what you want,
rather than getting lost in any of your potential lite-c errors.

C++ is more my native language than lite-c...

ALSO :: a block of sample text file will help,
and is this lite-c or c-script? (looks like c-script to me)

ALSO :: Cant figure out what wants to go where, the hack is confusing
things too much.
I'll be waiting on your C++ version.

Last edited by EvilSOB; 06/10/09 13:07.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: is there a end of file function? [Re: EvilSOB] #270959
06/10/09 17:59
06/10/09 17:59
Joined: Apr 2009
Posts: 18
F
FlyingRaven Offline OP
Newbie
FlyingRaven  Offline OP
Newbie
F

Joined: Apr 2009
Posts: 18
Originally Posted By: EvilSOB
Before I really read this post properly, I need more coffee,
BUT
Feel free to post the core of your C++ code so I can see what you want,
rather than getting lost in any of your potential lite-c errors.

C++ is more my native language than lite-c...

ALSO :: a block of sample text file will help,
and is this lite-c or c-script? (looks like c-script to me)

ALSO :: Cant figure out what wants to go where, the hack is confusing
things too much.
I'll be waiting on your C++ version.


well I hope you had your coffee becouse here is the info you requested.

yes this is c-script. and trust me I'm like I'm a c++ man and didn't even know lite-c/c-script before I started this project.

but right now I can't get to my c++ code since the hd I have it on doesn't work right now.
but this is what I am trying

- open the txt file. <--- goes semi well (problems listed in previus post)
- extract the questions at the top <---- goes well
- display the questions <--- works
- then select a question <--- works
- find text that belongss to the question <--- doesn't work (problems listed in previus post, but was the first try)
- then extract the text and print it. <-- would work if the one above it worked.

and this would be a test text
19 <--- max amount of lines
3 <--- where the program extracts it's first line
5 <--- amount of lines to extract
this is the test text
does it print a enter?
can I see al the text?
is everything working?
exit

this is the test text
12 <--- copy the text from this point
3 <--- the amount of lines
does this text show?
yes?
good.

etc

Re: is there a end of file function? [Re: FlyingRaven] #270989
06/10/09 18:54
06/10/09 18:54
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Still a little unclear, especially on the selection business, but I think I get it.
But where does the "gid01_choise_value" fit in?


If I understand correctly, you want...

The text file contains both the questions in the first batch of lines,
with the last line of the batch being "exit", at least in this example,
and the rest of the textfile contains the answers to those questions.

You want this function to read the entire textfile into a non-visible location,
copy the first batch of lines (including the 'exit' line) into a text box called "text".

The entire text file will remain in the text box called "buffer" ,
and the temp.x contains the total number of lines stored in buffer,
and the temp.y contains the starting place of the answer to the first question.

Is this correct?

Can I change it a bit?
I want to make the textfile contain (without any numbers stored)...
The questions
The word exit
A blank line, so code knows where questions end, and answers start
The answers.
Output will still be the same as I stated in my understanding above.

Is this OK?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: is there a end of file function? [Re: EvilSOB] #270997
06/10/09 19:19
06/10/09 19:19
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
If the above is OK, then try this
Code:
text buffer = { strings=25; }	//absolute maximum number of lines in a text file EVER

function getText()
{
	temp.x = txt_load(buffer, "text/test.txt");
	temp.y = 0;
	while(temp.y<temp.x)
	{
		if(str_len(buffer.string[temp.y])==1)
		{	temp.y+=1;		break;			}
		str_cpy(text.string[temp.y], buffer.string[temp.y]);
		temp.y += 1;
	}
	//temp.x is number of lines in the "buffer" text-object
	//temp.y is the first answer line. ie "buffer.string[temp.y]" is the first answer
}

and a sample text file is
Code:
test question 1
test question 2
test question 3
test question 4
exit
.              <<<<<Tis line HAS to be ONE character long
answer 1
answer 2
answer 3
answer 4


Last edited by EvilSOB; 06/10/09 19:22.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: is there a end of file function? [Re: EvilSOB] #271015
06/10/09 20:25
06/10/09 20:25
Joined: Apr 2009
Posts: 18
F
FlyingRaven Offline OP
Newbie
FlyingRaven  Offline OP
Newbie
F

Joined: Apr 2009
Posts: 18
oh thank you fore your answers and your code.
that actualy looks a bit like how I did it in c++.

but the temp.y is somthing I don't really know what it is but it was advised by me by some one else and since everything is so messed up right now I haven't checked if I can do with it it yet.
and the gid01_choice_value is the value of the question you picked.

but apart from that you seam to have it all right.

also the gid01 is from the plBiped01 cose you get with the lite-c when you instal it the people I am making the project fore are using that and it's not really making it any easyer XD

Last edited by FlyingRaven; 06/10/09 20:27.
Re: is there a end of file function? [Re: EvilSOB] #271017
06/10/09 20:27
06/10/09 20:27
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
The end of a file is reached if:
file_str_read, file_str_readto return -1
or if
file_var_read returns 0 (this seems a bit odd, as you should be able to store zeros in a file)

Information is taken from: the manual

Sorry if I did not understand your question.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1