fread problems
#1

Hello,
I've written a small function which reads a .txt file line by line. Depending on the text in this line the value should be saved in a specific variable.
That's the code:
pawn Код:
do
{
    i++;
    exists = true;
    format(path, 68, "/%s/%i.txt", dini_path, i);
    if(fexist(path))
    {
        ID[count] = i;
        count++;
        new File:report = fopen(path, io_read);
        while(fread(report, string))
        {
            if(strfind(string, "subject", true) != -1) { strdel(string, 0, 8); subject = string; }
            if(strfind(string, "time", true) != -1) { strdel(string, 0, 5); date = string; }
            if(strfind(string, "reason", true) != -1) { strdel(string, 0, 7); reason = string; }
            if(strfind(string, "read", true) != -1) { strdel(string, 0, 5); read = strval(string); }
            if(read) format(cat, 68, "{ED9E15}%s {FFFFFF}\t%s: %s\n", date, subject, reason);
            else format(cat, 68,"{ED9E15}%s {ED1515}\t%s: %s\n", date, subject, reason);
            strcat(msg, cat);
        }
        fclose(report);
    }
}
while(i<50);
if(!exists) return ShowPlayerDialog(playerid, 104, DIALOG_STYLE_MSGBOX, "Beschwerden", "Es sind aktuell keine Beschwerden eingetragen.", "Okay", "Nicht okay");
ShowPlayerDialog(playerid, 104, DIALOG_STYLE_LIST, "Beschwerden", msg, "Auswдhlen", "Abbrechen");
However, when I type in my command, the following dialog appears:

My guess certainly would be, that I mistyped the strdel at the start- and endingplace what from a new line would be formatted into the string. But I'm unable to see where the problem is.

The .txt file is built up in the following way:
Код:
reporter=Padarom
subject=Mike
reason=RegelverstoЯ
...
Hope you can help me.
They are created as followed:
pawn Код:
reporter=%s\nsubject=%s\nreason=%s\ndescription=%s\ntime=%s\nread=1
Regards
Padarom
Reply
#2

Yep, tried that. Strings were cut right. Edited the code a bit
pawn Код:
do
            {
                i++;
                format(path, 68, "/%s/%i.txt", dini_path, i);
                if(fexist(path))
                {
                    ID[count] = i;
                    count++;
                    exists = true;
                    new File:report = fopen(path, io_read);
                    while(fread(report, string))
                    {
                        if(strfind(string, "subject", true) != -1) { strdel(string, 0, 8); subject = string; }
                        if(strfind(string, "time", true) != -1) {  strdel(string, 0, 5);date = string; }
                        if(strfind(string, "reason", true) != -1) { strdel(string, 0, 7); reason = string; }
                        if(strfind(string, "read", true) != -1) { strdel(string, 0, 5); read = strval(string); }
                    }
                    if(read) format(cat, 68, "{ED9E15}%s {FFFFFF}%s: %s\n", date, subject, reason);
                    else format(cat, 68,"{ED9E15}%s {ED1515}%s: %s\n", date, subject, reason);
                    strcat(msg, cat);
                    fclose(report);
                }
            }
            while(i<50);
One problem is fixed now: There aren't any longer about 40 entries in the listbox (I formated the whole line in the while-loop). But now I have another problem: After every string is still a \n, which makes every variable appear in a new line, like this:
24.02.2012 15:59 -
Padarom
: Hack
23.02.2012 13:41 -
Mike
: Abuse

instead of
24.02.2012 15:59 - Padarom: Hack
23.02.2012 13:41 - Mike: Abuse
Reply
#3

I removed them, 'cause I couldn't see any problems in them. And afaik \n or \r (or in generally escape strings) are not printed at all. I printed the whole line (-> string) and after that the cut line (-> strdel(string)).
Reply
#4

Код:
BEFORE:
[17:39:27] "reporter=Padarom
"
[17:39:27] "subject=Padarom
"
[17:39:27] "reason=Beleidigung
"
[17:39:27] "description=Er nannte mich Arsch.
"
[17:39:27] "time=24.02.2012 13:27
"
[17:39:27] "read=1"
AFTER:
[17:44:20] "Padarom
"
[17:44:20] "Beleidigung
"
[17:44:20] "24.02.2012 13:27
"
[17:44:20] "1"
I only need those few strings atm.
That's the result. So the \r\n is after the last letter. So how to cut it off the best?
Reply
#5

Thank you ******, worked wonders so far
Reply
#6

Yes I did
Again, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)