SA-MP Forums Archive
File Read Problem - 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)
+--- Thread: File Read Problem (/showthread.php?tid=569761)



File Read Problem - Andrei1255 - 02.04.2015

Hi ! I made one script which when one leader invites one member in his faction, it saves automatically the name of the invited member into a file . When one leader types /wipe , the server should read that file and it should edit the user's file . But it reads one space at the end of the name, because of \n . Thus that space must be deleted . Do you know how to read the member's name without that extra space ? Thank you !


Re: File Read Problem - Jefff - 02.04.2015

pawn Код:
static len;
while((len = fread(file,string)))
{
    if(string[ len - 1 ] == '\n')
        string[ len - 1] = EOS;
}



Re: File Read Problem - Andrei1255 - 04.04.2015

When I use /wipe , the server restarts , look the code:

Код:
new File:hFile = fopen(string2, io_read);
			if(hFile)
			{
			        static len;
				    while((len = fread(hFile, Data, sizeof(Data))))
					{
					    if(strcmp(Data, PlayerName(playerid), true))
					    {
					        if(Data[ len - 1 ] == '\n')
									Data[ len - 1] = EOS;
					    
							new var[64];
							format(string, strlen(Data) - 1, "users/%s.ini", Data);
							SendClientMessage(playerid, COLOR_WHITE, string);
		       				new File:file = fopen(string, io_append);
		       				if(file)
		       				{
								SendClientMessage(playerid, COLOR_WHITE, "Test 1");
								format(var, sizeof(var), "Member=0\n"); fwrite(file, var);
								format(var, sizeof(var), "Team=3\n"); fwrite(file, var);
								format(var, sizeof(var), "Rank=0\n"); fwrite(file, var);
							 	format(var, sizeof(var), "FacWarns=0\n"); fwrite(file, var);
								format(var, sizeof(var), "Char=0\n"); fwrite(file, var);
							}
							
							fclose(file);
						}
					}
			}