Little help with strmid
#1

If I have to words in Forbidenwords ex:
Totalwords=2
Word_1=Fuck
Word_2=Shit
It only loads the first word
Why?
pawn Код:
function LoadForbidenWords()
{
    INI_Open("FAdmin/Logs/Forbidenwords.txt");
    if(INI_ReadInt("Totalwords") == 0) return 0;
    new totalwords = INI_ReadInt("Totalwords");
    new string[64];
    new key[20];
    for(new i = 1; i < totalwords;i++)
    {
        format(string, sizeof(string), "Word_%i", i), INI_ReadString(key,string),strmid(ForbidenWords[i], key, 0, 20, sizeof(ForbidenWords));
        printf("Words loaded: %s",ForbidenWords[i]);
    }
    INI_Close();
    return 1;
}
Reply
#2

pawn Код:
function LoadForbidenWords()
{
    INI_Open("FAdmin/Logs/Forbidenwords.txt");
    if(INI_ReadInt("Totalwords") == 0) return 0;
    new totalwords = INI_ReadInt("Totalwords");
    new string[64];
    new key[20];
    for(new i = 0; i < totalwords+1;i++)
    {
        format(string, sizeof(string), "Word_%i", i), INI_ReadString(key,string),strmid(ForbidenWords[i], key, 0, 20, sizeof(ForbidenWords));
        printf("Words loaded: %s",ForbidenWords[i]);
    }
    INI_Close();
    return 1;
}
problem was in loop.. you must start from 0!
problem 2 u format string but you don't do anything with it

EDIT1: You need add 1 more into varriable totalwords like you have 2 words but u must have 3!
Reply
#3

I don't think it's a good idea to use ini files for something like this. The name of the key is not important and therefor using ini is pointless. Using plain text file:
Код:
fuck
shit
bitch
pawn Код:
new
    File:handle = fopen("FAdmin/Logs/Forbidenwords.txt", io_read),
    word[32],
    i;

if(handle)
{
    while(fread(handle, word))
    {
        if(i >= sizeof(ForbiddenWords)) // Out of bounds protection
        {
            printf("Warning: Could not load more than %d words. Destination array is too small!");
            break;
        }
        strcpy(ForbidenWords[i], word);
        i++;
    }
    fclose(handle);
    printf("Words loaded: %d", i);
}
else printf("Forbidden words file not found, or it could not be opened!");
pawn Код:
stock strcpy(dest[], const source[], maxlength=sizeof dest)
{
    strcat((dest[0] = EOS, dest), source, maxlength);
}
I just typed this out of my head, but I think it would work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)