strcmp problem. [Unsolved] - 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 problem. [Unsolved] (
/showthread.php?tid=553823)
strcmp problem. [Unsolved] -
TheCoopster - 31.12.2014
Basically, I'm trying to use the strcmp function in a 'for' loop until it finds what it's looking for. I was making a vehicle MDC system using registration plates and such and I'm having a problem with strcmp. If I enter the correct registration it will show the correct vehicle registration. If I don't, it show's the same thing as if it was correct just with empty variables, as I will show below.
pawn Код:
Dialog:VehicleMDC(playerid, response, listitem, inputtext[])
{
if(response)
{
for(new i=0;i<MAX_CARS;i++)
{
if(strcmp(VehicleData[i][vPlate], inputtext, true) == 0)
{
new string[64];
//IC INFO (I haven't finished this yet, I was just testing it and it doesn't work)
format(string,sizeof(string),"Vehicle Registration: %s\n\n\n",VehicleData[i][vPlate]);
ShowDialog(playerid, MDC_VehicleShow, DIALOG_STYLE_MSGBOX,"MDC: Vehicle Database",string,"Continue","Back");
break;
}
}
}
else return 1;
}
Here are some screenshots of the problem.
WHEN I TYPE A VALID REGISTRATION:
WHEN I TYPE AN INVALID REGISTRATION:
Basically it shows the dialog when it shouldn't. It should just stop the loop and then nothing else should happen.
Re: strcmp problem. [Unsolved] -
TheCoopster - 31.12.2014
bump
Re: strcmp problem. [Unsolved] -
Vince - 31.12.2014
As it appears from your screenshots VehicleData[i][vPlate] is empty, and in that case strcmp will return 0. Try changing your statement to:
pawn Код:
if(!isnull(VehicleData[i][vPlate]) && strcmp(VehicleData[i][vPlate], inputtext, true) == 0)
Re: strcmp problem. [Unsolved] -
TheCoopster - 31.12.2014
Quote:
Originally Posted by Vince
As it appears from your screenshots VehicleData[i][vPlate] is empty, and in that case strcmp will return 0. Try changing your statement to:
pawn Код:
if(!isnull(VehicleData[i][vPlate]) && strcmp(VehicleData[i][vPlate], inputtext, true) == 0)
|
Oh okay that seems like it should work. Thanks for the help Vince. I'll give it a go.