Help with fread.
#1

I want to read the:
pawn Код:
if(dialogid == DIALOG_MDCNOME3)
{
      format(string, sizeof(string), "LSPD/Suspects/%s.ini", strlen(inputtext));
      //Read
      ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "-", string, "Ok", "Fechar");
}
I try to use while, but I don't get some results..
I want to read just 20 lines.

Thanks for your help.
Reply
#2

Use:

pawn Код:
if(dialogid == DIALOG_MDCNOME3)
{
    new count = 0, string[128];
   
    format(SkillBase, sizeof(SkillBase), "LSPD/Suspects/%s.ini", strlen(inputtext));
 
    while(fread(SkillBase, string))
    {
        // do what you want here
        count ++;
       
        if(count == 20)
        {
            break;
        }
    }

    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "-", string, "Ok", "Fechar");
}
Hope you understood.

@Vocк podia ter postado na PT/BR hehe
Reply
#3

I appreciate your help.

But I want to show the twenty lines.

Thanks,
Reply
#4

Ah I see. You can concatenate all the 20 lines in one master string and show it. As you're advanced in PAWN I won't document the code:

pawn Код:
if(dialogid == DIALOG_MDCNOME3)
{
    new count = 0, masterstring[256 /*maybe tmpstring > 128*/], tmpstring[128], line[128];

    format(SkillBase, sizeof(SkillBase), "LSPD/Suspects/%s.ini", strlen(inputtext));

    while(fread(SkillBase, line))
    {
        format(tmpstring, sizeof(tmpstring), "%s\r\n", line);
       
        strins(masterstring, tmpstring, strlen(masterstring));

        count ++;

        if(count == 20)
        {
            break;
        }
       
    }

    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "-", string, "Ok", "Fechar");
}
Reply
#5

Thanks, I'll see.
Reply
#6

You are formatting SkillBase as a string (%s) but the value you are passing is a integer. Substitute strlen(inputtext) with inputtext.
Reply
#7

So, I tryed to check, but doesn't show the dielog

pawn Код:
if(dialogid == DIALOG_MDCNOME3)
    {
        new count = 0, masterstring[1024], tmpstring[128], line[128];
        format(SkillBase, sizeof(SkillBase), "LSPD/Suspects/%s.ini", inputtext);
        new File:arquivo = fopen(SkillBase, io_read);
        while(fread(arquivo, line))
        {
            count ++;
            format(tmpstring, sizeof(tmpstring), "%s\n", line);
            strins(masterstring, tmpstring, strlen(tmpstring));
            if(count == 20) break;
        }
        ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, "-", masterstring, "Ok", "Fechar");
        SCM(playerid, -1, masterstring);
        return 1;
    }
Reply
#8

pawn Код:
if(dialogid == DIALOG_MDCNOME3)
{
        new count = 0, masterstring[1024], tmpstring[128], line[128];
        format(SkillBase, sizeof(SkillBase), "LSPD/Suspects/%s.ini", inputtext);
        new File:arquivo = fopen(SkillBase, io_read);
        while(fread(arquivo, line))
        {
            count ++;
            format(tmpstring, sizeof(tmpstring), "%s%s\n", tmpstring, line);
            strins(masterstring, tmpstring, strlen(tmpstring));
            if(count == 20) break;
        }
        ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, "-", masterstring, "Ok", "Fechar");
        SCM(playerid, -1, masterstring);
        return 1;
}
Try that.

Edit: Change the goddamn Dialog ID, set it to 'NULL (0)'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)