SA-MP Forums Archive
Space at the end of a string, fread() - 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: Space at the end of a string, fread() (/showthread.php?tid=82615)



Space at the end of a string, fread() - pascallj - 19.06.2009

Hello Everybody,

I am making my own server and everything is going well.

But now I've got a problem.

When I read the first line of a file with fread, it places a space at the end of the string.

This is my code:

Код:
		  new File:accname = fopen(nametxt, io_read);
		  
			new passwordtxt[20];
 			fread(accname, passwordtxt);
 			fclose(accname);
nametxt contains the name of the file that need to be opened.

If the file is:

Код:
password
adminfalse
passwordtxt is: "password " <- with a space at the end.

I hope anyone can explain the problem and help me.

Greetz,
Pascal

p.s. Sorry for my bad English, but I'm Dutch.


Re: Space at the end of a string, fread() - pascallj - 20.06.2009

--Sssst, still bumping...--

Anyone?


Re: Space at the end of a string, fread() - Joe Staff - 20.06.2009

strdel(passwordtxt,strlen(passwordtxt)-1,strlen(passwordtxt)); <- this deletes the last letter


Re: Space at the end of a string, fread() - ledzep - 20.06.2009

I've noticed this happens when loading strings from MySQL as well.


Re: Space at the end of a string, fread() - pascallj - 21.06.2009

Hmm, Now I noticed that it are 2 spaces zo I changed -1 to -2 and it still works. But why is it so weird?

Код:
strdel(passwordtxt,strlen(passwordtxt)-2,strlen(passwordtxt));
So what this in fact does is, that it deletes the characters from the length of the string -2 until the end of the string, don't it?


Re: Space at the end of a string, fread() - Andom - 21.06.2009

Because if you used \n it will make a new rule, and sometime pawno thinks that the end of a line end with a space.