Why not wrk? strcmp + reading file!
#1

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

make it call the function when the player join dont use while
Reply
#3

pawn Код:
if(!strcmp(string, player, true))
Reply
#4

pawn Код:
if(strfind(string, player, true) != -1)
Reply
#5

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

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] "
Reply
#7

Thanks! Works good..

Whats the deal with strcmp being a noob and not working? does it not work wit while loops?

thnx anyway, cheers
Reply
#8

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]
Reply
#9

Your probably reading the newline constant and thats why strcmp dont work.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)