SA-MP Forums Archive
Read out a config- file - 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: Read out a config- file (/showthread.php?tid=198183)



Read out a config- file - [MF]FACE - 11.12.2010

Hello to everybody around here,

I searched a long time ( in the sa-mp wiki too ) but couldn't find any solution for my problem.

I have a little text file in my scriptfiles and I want to read it out.
If one line says for example "version 0.5" I want to search for the string "version" and save the 0.5 in a variable.
I know how to read out a file with "fread" and but i can't extract different parts and split them up the like a version number.

It would be nice if s.o. is able to help me.


Re: Read out a config- file - legodude - 11.12.2010

sscanf is a helpful thing search for it on the wiki


Re: Read out a config- file - XePloiT - 11.12.2010

try this:
when you use it, its goes like this : split(TEXT,WHERE TO SAVE,WHERE TO SPLIT)
Exaple:
pawn Код:
new tmp[2][128];
split("Hello Dude!",tmp,' '); // tmp[0]=Hello tmp[1]=Dude!
The Script:
pawn Код:
stock split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}



Re: Read out a config- file - [MF]FACE - 11.12.2010

Nice one XePloit ,but there's still a problem I have. There are different lines and i don't know how to find out that there's one line sayin' "hello dude" and the other line saying "good morning" and it's all saved in 1 string.
if I'll print it there is written in the window:

hello dude

good morning


And know i want to search in the file for example for "hello"
and i want to extract exactly the thing after "hello" in the same line

How is it possible?

but the "splitter" is nice.


Re: Read out a config- file - MadeMan - 11.12.2010

Use the INI format

Код:
Version=0.5
and then try Dini (https://sampforum.blast.hk/showthread.php?tid=50)


Re: Read out a config- file - [MF]FACE - 11.12.2010

hmm, sounds nice but I only need this readout func. for 3 things.