Read out a config- file
#1

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

sscanf is a helpful thing search for it on the wiki
Reply
#3

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;
}
Reply
#4

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

Use the INI format

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)