Gamestudio Links
Zorro Links
Newest Posts
Purchase A8 full licence version
by ukgamer. 04/29/26 18:09
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Quad), 5,594 guests, and 72 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ukgamer, valino, juergenwue, VladMak, Geir
19210 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Read a text file line by line [Re: PadMalcom] #342704
09/30/10 09:28
09/30/10 09:28
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: PadMalcom
@Stromausfall: Problem is that one line might contain "\n" in between not only at the end.


Then look for the "\r\n" escape sequence.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Read a text file line by line [Re: WretchedSid] #342706
09/30/10 09:41
09/30/10 09:41
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Good idea wink

Re: Read a text file line by line [Re: PadMalcom] #342949
10/02/10 12:39
10/02/10 12:39
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
For all those who are interested in a solution:

Code:
STRING* file_read_line(var myHandle, int nLineNr) {
	if (!myHandle) return "";
	
	var oldPosition = file_seek(myHandle,0,4);
	STRING* res = str_create("#1000");
	
	// Find the right line
	file_seek(myHandle,0,0);
	
	int i;
	int j;
	for (i=0;i<=nLineNr;i++) {
		str_cpy(res,"");
		j = file_str_readto(myHandle,res, "\r\n", 1000);
		if (j == -1) {
			file_seek(myHandle,oldPosition,0);
			return "";
		}
		else
		{
			if (i == nLineNr) {
				file_seek(myHandle,oldPosition,0);
				return res;
			}
		}
	}
}



EDIT:
In addition a function to read the line count of a text file:
Code:
int file_count_lines(var myHandle) {
	if (!myHandle) return -1;
	
	var oldPosition = file_seek(myHandle,0,4);
	
	file_seek(myHandle,0,0);
	
	int res = 0;
	int j = 0;
	STRING* tempStr = str_create("#1000");
	while (1) {
		j = file_str_readto(myHandle,tempStr,"\r\n", 1000);
		if (j == -1) {
			break;
		}
		else
		{
			res +=1;
		}
	}
	file_seek(myHandle,oldPosition,0);
	return res;
}



Last edited by PadMalcom; 10/02/10 12:55.
Page 2 of 2 1 2

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