Read next line in file -
Skillet` - 08.10.2012
Hello,
How do I read from a file the next line from a file ?
for example :
File:
Код:
1#
Text 1
2#
Text 2
3#
Text 3
4#
Target text - This is my text ^.^
5#
Text 5
Now if I want to find number "4#" and read the text under that line and use it in the script,how do I do this without using any include ?
Re: Read next line in file -
Kwarde - 08.10.2012
Did you try to look at this page already?;
https://sampwiki.blast.hk/wiki/Fread
Re: Read next line in file -
Riddick94 - 08.10.2012
Which system do you using to save/load files.
Re: Read next line in file -
Kwarde - 08.10.2012
Quote:
Originally Posted by Riddick94
Which system do you using to save/load files.
|
Quote:
how do I do this without using any include ?
|
So I assume he isn't using any "systems"
Re: Read next line in file -
Riddick94 - 08.10.2012
He need to use atleast an a_samp include..
Alright, just kidding now. Well, the solution is obvious and ready on Wiki.
Re: Read next line in file -
Kwarde - 08.10.2012
Well, I'm not sure if the solution is THAT obvious. Because this guy over here is asking to find something in the file by searching for "4#", and the fread (on the SA:MP Wiki) only shows how to read line-by-line. However, it still should be easy ;p
Re: Read next line in file -
ReneG - 08.10.2012
There is currently no function to specify which lines to search by, but this may work.
PHP код:
stock readfile()
{
new
File:file = fopen("file.txt", io_read),
string[128],
foundline = 0;
while(fread(file, string, sizeof(string)) {
if((strfind(string, "#4") != -1) && !foundline) {
foundline = 1;
continue;
}
if(foundline) {
printf("%s", string);
}
}
return 1;
}
Very impractical though.
Re: Read next line in file -
Skillet` - 08.10.2012
Quote:
Originally Posted by Kwarde
Well, I'm not sure if the solution is THAT obvious. Because this guy over here is asking to find something in the file by searching for "4#", and the fread (on the SA:MP Wiki) only shows how to read line-by-line. However, it still should be easy ;p
|
No,actually the point was to direct the pawn to the line I want to extract and pack it into a string without searching for a string.
Quote:
Originally Posted by VincentDunn
There is currently no function to specify which lines to search by, but this may work.
PHP код:
stock readfile()
{
new
File:file = fopen("file.txt", io_read),
string[128],
foundline = 0;
while(fread(file, string, sizeof(string)) {
if((strfind(string, "#4") != -1) && !foundline) {
foundline = 1;
continue;
}
if(foundline) {
printf("%s", string);
}
}
return 1;
}
Very impractical though.
|
Skipping lines ? smart,didn't thought about this.
anyway,found a solution,thanks you all for trying to help.
Re: Read next line in file -
ReneG - 09.10.2012
Would you mind sharing this? I'm curious as well.