SA-MP Forums Archive
[Help] Parsing files - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Help] Parsing files (/showthread.php?tid=115897)



[Help] Parsing files - Gvdsloot - 26.12.2009

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.


Re: [Help] Parsing files - dice7 - 26.12.2009

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);



Re: [Help] Parsing files - Gvdsloot - 26.12.2009

I want to strip it, I only want the content after the =


Re: [Help] Parsing files - dice7 - 26.12.2009

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


Re: [Help] Parsing files - Gvdsloot - 27.12.2009

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


Re: [Help] Parsing files - [HiC]TheKiller - 27.12.2009

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


Re: [Help] Parsing files - Gvdsloot - 27.12.2009

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