[Help] Parsing files
#1

Hello, I want to parse the following, but I don't know how to do it:

a = 20
b = 25

I read the tutorial about File Functions but I don't understand the read part because the tutorial doesn't describes what the functions are doing so I have no clue how to work with them, can anybody explain it to me, please?
Thanks.
Reply
#2

https://sampwiki.blast.hk/wiki/File_Functions
https://sampwiki.blast.hk/wiki/Fread
https://sampwiki.blast.hk/wiki/Fwrite
https://sampwiki.blast.hk/wiki/Fopen
https://sampwiki.blast.hk/wiki/Fexist
https://sampwiki.blast.hk/wiki/Fclose

pawn Код:
new File:Handler;
    new path[20];
    new string[50];
    new idx = 1;
    format(path, 19, "folder/text.txt"); //this is the path inside the scriptfiles folder
    if(fexist(path))
    {
        //file exists
        Handler = fopen(path, io_read); //io_read is the opening mode
        while(fread(Handler, string)) //reads one line from the file and stores it in "string". If the reading was succesfull, it will return true and the code in the while loop will execute, else it will move on
        {
            printf("Line %d has the following written: %s", idx, string);
            idx++;
        }
    }
Everytime you use fread(), it will read the next line in line. You use a loop if you don't know how long the file is.
For reading the first 3 lines you could just do this
pawn Код:
Handler = fopen(path, io_read);
    fread(Handler, string);
    printf("Line 1 data: %s", string);
    fread(Handler, string);
    printf("Line 2 data: %s", string);
    fread(Handler, string);
    printf("Line 3 data: %s", string);
Reply
#3

I want to strip it, I only want the content after the =
Reply
#4

Then use a string manipulator, something like strtok or sscanf.
Or just use dini for saving info
Reply
#5

Isn't there a function to split a string into arrays?
Reply
#6

Use Dini, it's function Dini_intSet and Dini_Int is exactly what you want.
Reply
#7

I tried dini out, and I love it.
It's EXACTLY where I was looking for.
Thank you so much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)