Load a file from another file - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Load a file from another file (
/showthread.php?tid=172437)
Load a file from another file -
ppanlie - 30.08.2010
Hi..
I made a file where is other file names , and when i want to load files , the server call me as the file don't exist,I put a 'printf' and print in console this:
PHP код:
ERROR: I can't open file: maps/aa
.m
How i can delete that \r\n?
Re: Load a file from another file -
Backwardsman97 - 30.08.2010
I don't understand what you're saying.
Re: Load a file from another file -
ppanlie - 30.08.2010
If i put the code you will understand
pawn Код:
stock LoadMaps()
{
new string[256];
new File:Handler=fopen("Maps.l",io_read);
while(fread(Handler,string))
{
new str[256];
format(str,256,"%s.m",string);
if(!fexist(str))
{
printf("ERROR: I can't open file: %s",str);
break;
}
//blabla
}
fclose(Handler);
return 1;
}
file Maps.l:
And in console:
PHP код:
[22:11:29] ERROR: I can't open file: Test
.m
Re: Load a file from another file -
Voldemort - 30.08.2010
Код:
new File:Handler=fopen("Maps.l",io_read);
while(fread(Handler,string))
{
new str[256];
format(str,256,"%s.m",string);
What is the right format of file? *.l or *.m ??
and why you need new string[256]; 2x ?? use string[64]; and only once, Im sure you dont have any file name longer than 64 symbols
Re: Load a file from another file -
Simon - 30.08.2010
I think this may be a SA:MP bug, although I'm not sure. I don't think it used to happen? Anyhow, in order to fix it you have to manually loop through the array and find the \r\n, once you find them then set them to 0 (string terminator)
e.g.
You could do something like this (untested) function to terminate the string at a new line, which should be fine for fread as it works line by line (i.e. \r\n)..
pawn Код:
TerminateNL(string[], start = 0, len = sizeof string)
{
// It's assumed a string so we'll make sure it has a null terminator at the end.
string[len-1] = 0;
while(string[++start]) {
if (string[start] == '\r' || string[start] == '\n')
string[start] = 0; // You could put a "break;" statement here if you wish to not terminate all NL characters for efficiency. The string should "end" when it reaches the first string terminator.
}
}