Little help overwriting a line of a file
#7

You can use this function

pawn Код:
stock freplaceline(filename[], find[], replace[])
{
    if(!fexist(filename)) return 0;
    new File:handle = fopen(filename, io_read);
    if(!handle) return 0;
    new File:tmp = ftemp();
    if(!tmp)
    {
        fclose(handle);
        return 0;
    }
    new line[256];
    while(fread(handle, line))
    {
        if(strfind(line, find) == -1)
            fwrite(tmp, line);
        else
            fwrite(tmp, replace);
    }
    fclose(handle);
    fseek(tmp, 0);
    handle = fopen(filename, io_write);
    if(!handle)
    {
        fclose(tmp);
        return 0;
    }
    while(fread(tmp, line))
    {
        fwrite(handle, line);
    }
    fclose(handle);
    fclose(tmp);
    return 1;
}
pawn Код:
public LastGunShopDate(playerid)
{
    new str[128], sstr[128];
    new year,month,day;
    getdate(year, month, day);
    format(str, sizeof(str), "Gunshop:%d",P_Info[playerid][gunkey]);
    format(sstr, sizeof(sstr), "GunShop:%d - Date:%02d|%02d|%d\r\n",P_Info[playerid][gunkey],day,month,year);
    freplaceline("guns.cfg",str,sstr);
    return 1;
}
Reply


Messages In This Thread
Little help overwriting a line of a file - by Mishima - 29.05.2012, 19:21
Re: Little help overwriting a line of a file - by Jonny5 - 29.05.2012, 20:05
Re: Little help overwriting a line of a file - by Mishima - 29.05.2012, 20:31
Re: Little help overwriting a line of a file - by Mishima - 30.05.2012, 11:36
Re: Little help overwriting a line of a file - by Jonny5 - 30.05.2012, 11:45
Re: Little help overwriting a line of a file - by Mishima - 31.05.2012, 14:00
Re: Little help overwriting a line of a file - by MadeMan - 31.05.2012, 16:15
Re: Little help overwriting a line of a file - by Mishima - 31.05.2012, 16:50

Forum Jump:


Users browsing this thread: 3 Guest(s)