How to go through all the rows in file ?
#1

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


sorry my bad englishh
Reply
#2

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.
}
Reply
#3

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

help
Reply
#5

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

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

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;
}
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)