SA-MP Forums Archive
Reading and printing out variables via fread +REP - 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: Reading and printing out variables via fread +REP (/showthread.php?tid=604958)

Pages: 1 2


Re: Reading and printing out variables via fread +REP - Amit1998 - 12.04.2016

Quote:
Originally Posted by Godey
View Post
I'm not used to File I/O's but I will try to help you.
Try using
Code:
fseek (cfg, 28, SEEK_SET);
EDIT: btw why you used this 2 times?
Code:
ireason = fread(cfg, strinsg); // over here 
ireason = fread(cfg, strinsg); // over here
I used it twice in order to reach out to the 2nd line inside the .lock file(The reason).
Where should I put the fseek in order to get the string of the 2nd row?


Re: Reading and printing out variables via fread +REP - NaS - 12.04.2016

If you want to stick with fread, just use it like this:

Code:
fread(cfg, strinsg, sizeof(strinsg));
No need to save the return value.

If you want to use fseek, put that before the fread, however the 28 Godey put in has to be calculated from the players' name length PLUS the number of returns (1 if you use "\n", 2 if you use "\r\n").


Re: Reading and printing out variables via fread +REP - Godey - 12.04.2016

If your using that, then there's no need for fseek();


Re: Reading and printing out variables via fread +REP - Amit1998 - 12.04.2016

......


Re: Reading and printing out variables via fread +REP - Amit1998 - 12.04.2016

Quote:
Originally Posted by Godey
View Post
If your using that, then there's no need for fseek();
I'm hopeless heh'. How you adjust it to the fseek function ? >:


Re: Reading and printing out variables via fread +REP - NaS - 12.04.2016

I don't see why it doesn't work.
Are you using the windows editor to create the file or WordPad? The Editor does only use \r and depending on the settings it may be read as one whole line. Try to either remove one fread (for testing) or save the file correctly with WordPad.


Re: Reading and printing out variables via fread +REP - Amit1998 - 12.04.2016

......


Re: Reading and printing out variables via fread +REP - NaS - 12.04.2016

\r should be put before \n, since the text itself is correct that should be the cause.


Re: Reading and printing out variables via fread +REP - Godey - 13.04.2016

NaS is right, your order is incorrect
Code:
        new File:Hwban = fopen(Line, io_append); 
        format(iStr, sizeof(iStr), "%s\r\n", PlayerName(User)); 
        fwrite(Hwban, iStr); 
        format(iStr, sizeof(iStr), "\r\n%s", iReason); 
        fwrite(Hwban, iStr); 
        fclose(Hwban);



Re: Reading and printing out variables via fread +REP - Crayder - 13.04.2016

Why not use just one format and fwrite though

pawn Code:
new File:Hwban = fopen(Line, io_append);
        format(iStr, sizeof(iStr), "%s\r\n%s\r\n", PlayerName(User), iReason);
        fwrite(Hwban, iStr);
        fclose(Hwban);



Re: Reading and printing out variables via fread +REP - Amit1998 - 13.04.2016

......


Re: Reading and printing out variables via fread +REP - NaS - 13.04.2016

In OnPlayerConnect - You have to format iStr like this at the end:

Code:
format(iStr, sizeof(iStr), "Reason: %s", strinsg);
and change the fread lines to
Code:
fread(cfg, strinsg); // over here 
fread(cfg, strinsg); // over here
No need to assign the return value to ireason, you can remove that variable.