Read next line in file
#1

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

Did you try to look at this page already?; https://sampwiki.blast.hk/wiki/Fread
Reply
#3

Which system do you using to save/load files.
Reply
#4

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"
Reply
#5

He need to use atleast an a_samp include.. Alright, just kidding now. Well, the solution is obvious and ready on Wiki.
Reply
#6

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

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(filestringsizeof(string)) {
        if((
strfind(string"#4") != -1) && !foundline) {
            
foundline 1;
            continue;
        }
        
        if(
foundline) {
            
printf("%s"string);
        }
    }
    return 
1;

Very impractical though.
Reply
#8

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(filestringsizeof(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.
Reply
#9

Would you mind sharing this? I'm curious as well.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)