AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   equali() problem (https://forums.alliedmods.net/showthread.php?t=75839)

ceribik 08-13-2008 08:16

equali() problem
 
Hello. I've got the following code below; which in summary, reads a file and sees if the current map is listed in the file. For an unknown reason, the comparation of the two strings (mapname and data) isn't working and makes function output false

Code:

new mapname[33];

...

public plugin_init()
{
      get_mapname(mapname, 31);
}

...

stock checkLevelMap()
{
    new listFilename[256];
   
    new confFolder[32];
    get_configsdir(confFolder, 31);
    format(listFilename, 255, "%s/levelmaps.ini", confFolder);
   
    if( file_exists(listFilename) )
    {
        new file = fopen(listFilename, "rt");
       
        new data[64];
        while( !feof(file) )
        {
            fgets(file, data, 63);
           
            server_cmd("echo data == %s", data);
           
            if( equali(mapname, data) )
            {
                fclose(file);
               
                return true;
            }
           
        }
       
        fclose(file);
       
        return false;
    }
    else
    {
        log_amx("[SurfLife] Could not load levelmaps.ini");
    }

   
    return false;
}

Any help would be appreciated :)

Arkshine 08-13-2008 08:21

Re: equali() problem
 
Try to insert 'trim( data )' just after 'fget()'.

ceribik 08-14-2008 03:16

Re: equali() problem
 
That appears to have done the trick. Thanks again :)

Arkshine 08-14-2008 03:21

Re: equali() problem
 
Because some spaces are presents, probably.

Greenberet 08-14-2008 11:40

Re: equali() problem
 
not spaces
line feed ;)
fgets doesn't remove '\n' at the end of the string

ceribik 08-15-2008 10:06

Re: equali() problem
 
Quote:

Originally Posted by Greenberet (Post 669497)
not spaces
line feed ;)
fgets doesn't remove '\n' at the end of the string

That's what i was thinking too :)


All times are GMT -4. The time now is 09:50.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.