SA-MP Forums Archive
How to go through all the rows in file ? - 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: How to go through all the rows in file ? (/showthread.php?tid=553410)



How to go through all the rows in file ? - _Application_ - 29.12.2014

How to go through all the rows, (curses file)


sorry my bad englishh


Re: How to go through all the rows in file ? - Schneider - 29.12.2014

pawn Код:
new File:file;
file=fopen("YourFile.txt", io_read);
new string[128];
while(fread(file, string))  // Loop through each line in the file
{
    //the row is stored in 'string', do whatever you want to do with it.
}



Re: How to go through all the rows in file ? - _Application_ - 29.12.2014

Quote:
Originally Posted by Schneider
Посмотреть сообщение
pawn Код:
new File:file;
file=fopen("YourFile.txt", io_read);
new string[128];
while(fread(file, string))  // Loop through each line in the file
{
    //the row is stored in 'string', do whatever you want to do with it.
}
It only takes a last curse into a in file :/

Swears.ini ->
fuck // not work
idiot // not work
bitch // not work
noob // work


Re: How to go through all the rows in file ? - _Application_ - 29.12.2014

help


Re: How to go through all the rows in file ? - SickAttack - 29.12.2014

pawn Код:
new string[144], File:file = fopen("/Server/Registered Players.cfg", io_read);
if(file)
{
    while(fread(file, string))
    {
        SendClientMessage(playerid, -1, string);
    }
}
fclose(file);



Re: How to go through all the rows in file ? - _Application_ - 29.12.2014

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
pawn Код:
new string[144], File:file = fopen("/Server/Registered Players.cfg", io_read);
if(file)
{
    while(fread(file, string))
    {
        SendClientMessage(playerid, -1, string);
    }
}
fclose(file);
PHP код:
public OnPlayerText(playeridtext[])
{
    new 
string[144], File:file fopen(FILE_SWEARSio_read);
    if(
file)
    {
        while(
fread(filestring))
        {
            
Censor(textstring);
        }
    }
    
fclose(file);
    return 
1;

It only takes a last curse into a in file :/

Swears.ini ->
fuck // not work -> fuck
idiot // not work -> idiot
bitch // not work -> bitch
noob // work -> ****


Re: How to go through all the rows in file ? - Schneider - 29.12.2014

I debuged it and it seems fread also gets the newline character ( \n )
so in fact it looks for example "idiot\n" in the players text. I don't know if there's a better way to do it, but if you remove that character it works:

pawn Код:
public OnPlayerText(playerid, text[])
{
    new str[32], File:file = fopen(FILE_SWEARS, io_read), pos;
    while(fread(file, str))
    {
        pos = strfind(str, "\n", true, 0);
        if(pos != -1) strdel(str, pos-1, pos+1);
        if(strfind(text, str, true, 0) != -1)
        {
            Censor(text, string);
            fclose(file);
            return 0;
        }
    }
    fclose(file)
    return 1;
}



Re: How to go through all the rows in file ? - _Application_ - 30.12.2014

Quote:
Originally Posted by Schneider
Посмотреть сообщение
I debuged it and it seems fread also gets the newline character ( \n )
so in fact it looks for example "idiot\n" in the players text. I don't know if there's a better way to do it, but if you remove that character it works:

pawn Код:
public OnPlayerText(playerid, text[])
{
    new str[32], File:file = fopen(FILE_SWEARS, io_read), pos;
    while(fread(file, str))
    {
        pos = strfind(str, "\n", true, 0);
        if(pos != -1) strdel(str, pos-1, pos+1);
        if(strfind(text, str, true, 0) != -1)
        {
            Censor(text, string);
            fclose(file);
            return 0;
        }
    }
    fclose(file)
    return 1;
}
What you've done here is
\ n
Each row?