Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, henrybane, AndrewAMD), 1,343 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
File paths in strings - problem with a tiny "\" #395673
02/26/12 14:40
02/26/12 14:40
Joined: Nov 2008
Posts: 946
T
the_clown Offline OP
User
the_clown  Offline OP
User
T

Joined: Nov 2008
Posts: 946
Okay, so I got the following problem:

I'm trying to open a text file in my project folder. So far so good, I got the following function:

Code:
function file_load(STRING* fileName)
{
      // firstly, create a file handle

	var myFileHandle;

	// now, do the annoying string hickup to open the file in the correct folder:
	
	STRING* fileToGet = " ";


	str_cpy(fileToGet,"%EXE_DIR%\\");

	str_cat(fileToGet,fileName);

	//	return(fileToGet);
	// open the file
	
	myFileHandle = file_open_read(fileToGet);
	error(fileToGet);
	error(str_for_num(NULL,myFileHandle));
	
}




Now, what I'd expect to happen now is that the error boxes popping up show me the path I wanna access, which should be my project folder (I got no subfolders) and the handle I get when accessing the file. The file does physically exist in the folder.
What I get in the box however is not this:

%EXE_DIR%\\myFile.txt

but this:

%EXE_DIR%\myFile.txt

As you can see, one "\" is missing; accordingly, I get a zero as file handle value as the folder the script tries to open doesnt exist.

I tried and put an
Code:
error("\\")



with a varying number of "\"s, and I always got only one "\" back - if I put an uneven number of them in the string, I get a syntax error at compiling.
Now, am I missing something about strings here? Is there a logical reason why the "\"s seem to vanish?

Re: File paths in strings - problem with a tiny "\" [Re: the_clown] #395676
02/26/12 14:43
02/26/12 14:43
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline
Expert
fogman  Offline
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany
Quote:
Special characters within a string must be preceded by a '\': \n - Line feed; \\ - Backslash; \" - Quotation mark.


http://www.conitec.net/beta/astring.htm


no science involved
Re: File paths in strings - problem with a tiny "\" [Re: fogman] #395678
02/26/12 14:59
02/26/12 14:59
Joined: Nov 2008
Posts: 946
T
the_clown Offline OP
User
the_clown  Offline OP
User
T

Joined: Nov 2008
Posts: 946
Aaahh, okay. Must have overseen this. Thanks, fogman.

EDIT: Hmm, from what is said there a "\\" would have to be written like this:

"\\\\"

However, this still writes only one "\"; this "\\ \\" correctly translates into "\ \", however, this isn't of much use when trying to open the file. On the other hand, a "\\\\\\" (with six chars) translates into the desired "\\"; In the examples in the manual, they only write TWO backslashes in the file path strings. I'm quite confused right now, especially because i have the felling I'm missing something obvious. confused


EDIT NO.2:

Plus, now the compiler tells me "file_dialog" is a undeclared identifier - what it shouldn't do, should it?
All using the free A8.

EDIT No.3:

Okay, I did miss the fact that one uses SINGLE backslashes in file paths, not pairs... so, my core issues are solved, yet the undeclared identifier problem remains.
EDITED THE EDIT:

Okay, seems like you have to manually include the "strio.c". Everything works as it should now.

Last edited by the_clown; 02/26/12 15:33.
Re: File paths in strings - problem with a tiny "\" [Re: the_clown] #395693
02/26/12 18:05
02/26/12 18:05
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
it's not okay there: STRING* fileToGet = " ";

you should use: STRING* fileToGet = str_create("");


Free world editor for 3D Gamestudio: MapBuilder Editor

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

Gamestudio download | chip programmers | 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