strcmp not working
#1

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)
Reply
#2

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
Reply
#3

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
Reply
#4

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)