fwrite(file [Add 1]??
#1

So i wonder if i can add 1 with "fwrite"?

So let's say i have 0 in the file and i want to add 1, it increases to 1, then if i do the same command again it should add on the 1 that already exist so it makes it 2?
Reply
#2

either use some dini system or whatever or something like that:
pawn Код:
new tmp[10];
new File:myfile = fopen("yourfile.txt", io_readwrite);
fread(myfile, tmp);
format(tmp, sizeof(tmp), "%d", strval(tmp) + 1);
fwrite(myfile, tmp);
fclose(myfile);
although this might be the least efficient way
Reply
#3

Deleted.
Reply
#4

Quote:
Originally Posted by BleverCastard
Посмотреть сообщение
Deleted.
What do you mean "Deleted"?
Reply
#5

Quote:
Originally Posted by kevannkw
Посмотреть сообщение
What do you mean "Deleted"?
he wrote some message there and might have noticed that what he wrote was wrong or whatever, therefor he replaced it with "deleted" with what he means "just ignore this"
Reply
#6

You have to open the file as read-only, read the contents, close the file, open the file as write-only, write the contents and close the file.

pawn Код:
stock AddOneToFile(file[])
{
     new File:handle = fopen(file, io_read), buf[6];

if(handle)
{
    fread(handle, buf);
    number = strval(buf);
    fclose(handle);
    new File:handle = fopen(file, io_write);

    if(handle)
    {
        fwrite(handle, number+1);
       
        fclose(handle);
    }
}

return 1;
}
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
Or you could save several stages by opening the file as readwrite.
Mind giving me an Example?
Reply
#8

Quote:
Originally Posted by Sascha
Посмотреть сообщение
either use some dini system or whatever or something like that:
pawn Код:
new tmp[10];
new File:myfile = fopen("yourfile.txt", io_readwrite);
fread(myfile, tmp);
format(tmp, sizeof(tmp), "%d", strval(tmp) + 1);
fwrite(myfile, tmp);
fclose(myfile);
although this might be the least efficient way
well I wrote this already
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)