SA-MP Forums Archive
strcmp not working - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: strcmp not working (/showthread.php?tid=569941)



strcmp not working - Jack_Leslie - 04.04.2015

This should work right?
pawn Код:
for(new i = 0; i < sizeof(pVeh); i++)
                {
                    if(strcmp(pVeh[i][car_Plate], string, false) == 0)
                    {
                        exist = 1;
                        break;
                    }
                }
                if(exist == 1)
                {
                    ErrorMessage(playerid, "That number plate already exists on another vehicle!");
                    format(string, sizeof(string), "You are setting your plate for your %s. This will cost $75 and There's a few guidelines.\n\n* Can only be 34 characters long.\n* Has to be unique.\n* Any unrealistic plates seen will be changed by an admin", GetVehicleFriendlyName(SettingPlate[playerid]));
                    ShowPlayerDialog(playerid, DIALOG_VEH_PLATE, DIALOG_STYLE_INPUT, "Vehicle Number Plate", string, "Submit", "Cancel");
                    return 1;
                }
But when the string is the same, it doesn't run if(exist == 1)


Re: strcmp not working - De4dpOol - 04.04.2015

pawn Код:
for(new i = 0; i < sizeof(pVeh); i++)
                {
                    if(!strcmp(pVeh[i][car_Plate], string, false) == 0)
                    {
                        exist = 1;
                        break;
                    }
                }
                if(exist == 1)
                {
                    ErrorMessage(playerid, "That number plate already exists on another vehicle!");
                    format(string, sizeof(string), "You are setting your plate for your %s. This will cost $75 and There's a few guidelines.\n\n* Can only be 34 characters long.\n* Has to be unique.\n* Any unrealistic plates seen will be changed by an admin", GetVehicleFriendlyName(SettingPlate[playerid]));
                    ShowPlayerDialog(playerid, DIALOG_VEH_PLATE, DIALOG_STYLE_INPUT, "Vehicle Number Plate", string, "Submit", "Cancel");
                    return 1;
                }
The above code should work fine Added a (!) before strcmp.
Strcmp returns 0 if string matches and returns 1 or -1 if they don't.
https://sampwiki.blast.hk/wiki/Strcmp


AW: Re: strcmp not working - Kaliber - 04.04.2015

Quote:
Originally Posted by De4dpOol
Посмотреть сообщение
Strcmp returns 0 if string matches
Thats why he checked it...with == 0...to write ! or == 0 is the same

The Problem is, he must write it like this:

PHP код:
if(!strcmp(pVeh[i][car_Plate], stringfalse) && pVeh[i][car_Plate][0] != '\0'
Greekz


Re: AW: Re: strcmp not working - De4dpOol - 04.04.2015

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Thats why he checked it...with == 0...to write ! or == 0 is the same
Thanks for fixing me


Re: AW: Re: strcmp not working - Jack_Leslie - 04.04.2015

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Thats why he checked it...with == 0...to write ! or == 0 is the same

The Problem is, he must write it like this:

PHP код:
if(!strcmp(pVeh[i][car_Plate], stringfalse) && pVeh[i][car_Plate][0] != '\0'
Greekz
Sweet, thanks.