Posts: 243
Threads: 73
Joined: Sep 2013
Reputation:
0
Hey,
I've been trying to make a unique system for my server. Basically it creates a file via the File Functions native and I'd like it to print out something from the very same file after it's done. The file itself contains two lines, the player's name and another string. How can I print out the 2nd line in the file?
Thanks in advance!
Posts: 1,801
Threads: 21
Joined: Mar 2008
Reputation:
0
If they are split by lines (\r\n or \n) it's way easier to use just fread.
fread will read one line only, so if you do fread twice after opening, the string will contain the second line.
It will return 1 if there is content, 0 if not.
fseek is possible too, but you need to know the exact position of the starting point of line 2 (which is in your case length of playername plus 1 or 2 (depending on if you used "\n" or "\r\n")).
Posts: 150
Threads: 5
Joined: Jun 2015
Reputation:
0
I recommend fseek(); always!
It gives the EXACT address of the pointer variable.
Since fread(); comes handy only during (\n(s)) are used, why not use fseek(); always and get used to it? It will be handy when you have major saved string data's
But in this case as NaS said, you can use fread();
Posts: 150
Threads: 5
Joined: Jun 2015
Reputation:
0
Try replacing Location with ireason?
Posts: 243
Threads: 73
Joined: Sep 2013
Reputation:
0
It prints out the kick message like this:
Name: PlayersName
HC: PlayersGPCI
Reason: /HardwareBans/KLAJSD123098JHWHAJ.lock
When it should print the reason rather than the location.
Posts: 150
Threads: 5
Joined: Jun 2015
Reputation:
0
Ok see, by default ireason is saving as the pointer of ireason (that is the location!)
so you need to withdraw the particular reason from the file, not it's location.
Are you sure the file which you are loading (cfg) has the Reason: string value?
Posts: 243
Threads: 73
Joined: Sep 2013
Reputation:
0
Hum the file itself looks like this from inside:
"Amit_Godey"
"Hacking"
for e.g ofc
Posts: 150
Threads: 5
Joined: Jun 2015
Reputation:
0
Have you used fseek(); to jump to the second line and then read the string?
Posts: 243
Threads: 73
Joined: Sep 2013
Reputation:
0
Nope lol I couldn't understand the use of it. Mind editing it up for me or briefly explain what I should do? >: