Reading and printing out variables via fread +REP
#21

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

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").
Reply
#23

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

......
Reply
#25

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 ? >:
Reply
#26

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.
Reply
#27

......
Reply
#28

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

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

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

......
Reply
#32

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


Forum Jump:


Users browsing this thread: 1 Guest(s)