Why not wrk? strcmp + reading file! -
BMUK - 01.10.2009
pawn Код:
new player[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid,player,sizeof(player));
new File:file = fopen("armysafe.txt",io_read);
while(fread(file,string,sizeof(string)))
{
if(strcmp(string, player, true))
{
SendClientMessage(playerid,COLOR_RED,"Yes, your name is in the file called armysafe.txt");
printf("%s",string);
}
}
I had 20 names in the file. One of which was the name I am connected with but it dont detect it?
Re: Why not wrk? strcmp + reading file! -
brett7 - 01.10.2009
make it call the function when the player join dont use while
Re: Why not wrk? strcmp + reading file! -
Jamesy - 01.10.2009
pawn Код:
if(!strcmp(string, player, true))
Re: Why not wrk? strcmp + reading file! -
dice7 - 01.10.2009
pawn Код:
if(strfind(string, player, true) != -1)
Re: Why not wrk? strcmp + reading file! -
BMUK - 01.10.2009
Quote:
Originally Posted by dice7
pawn Код:
if(strfind(string, player, true) != -1)
|
Tried it.. lol
It would return true for a player with BM[UK]SUX too
Re: Why not wrk? strcmp + reading file! -
dice7 - 01.10.2009
pawn Код:
format(str, sizeof(str), "%c%s%c", ' ', player, ' ');
while(fread(file,string,sizeof(string)))
{
if(strfind(string, str, true) != -1)
{
SendClientMessage(playerid,COLOR_RED,"Yes, your name is in the file called armysafe.txt");
printf("%s",string);
}
}
Untested, but it should work. It will search for " BM[UK] "
Re: Why not wrk? strcmp + reading file! -
BMUK - 01.10.2009
Thanks! Works good..
Whats the deal with strcmp being a noob and not working? does it not work wit while loops?
thnx anyway, cheers
Re: Why not wrk? strcmp + reading file! -
dice7 - 01.10.2009
because your strcmp was wrong
pawn Код:
if(strcmp(string, player, true))
strcmp returns 0 if strings match, 1 is str1 is greater then str2 and -1 if str2 is greater.
You would need to do
pawn Код:
if(!strcmp(string, player, true))
And the comparing string (str1) was a whole line from a file. I don't know your file structure, but you probably have more text written in a line, then just BM[UK]
Re: Why not wrk? strcmp + reading file! -
Jamesy - 01.10.2009
Your probably reading the newline constant and thats why strcmp dont work.
Re: Why not wrk? strcmp + reading file! -
BMUK - 01.10.2009
This is what was in my .txt file
Код:
jimmy
Jonny
BM[UI]
BM[UK]gg
Kimmy
Rt43
FgtEss
BM[UK]
Kimmy
Rt43
FgtEss
This is why Im stumped as to why it not worky!
I tried if(!strcmp(string, player, true)) also

strange
Edit: im using your code dice so im not bothered much.. I was sitting here for a good 2 hours wondering why my strcmp wasnt playing

lol