strcmp problem. [Unsolved]
#1

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

bump
Reply
#3

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)