Space at the end of a string, fread()
#1

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.
Reply
#2

--Sssst, still bumping...--

Anyone?
Reply
#3

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

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

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?
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)