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
1 registered members (Dico), 16,767 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
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 | 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