strcmp phone number
#1

Whats wong with this?
Код:
if(strcmp(inputtext, "911") == 0)
{
   //do something if inputtext 911 (police, ems etc.)
}
else
{
   foreach(Player, i)
   {
       if(strcmp(PlayerInfo[i][pPhnumber], inputtext) == 0)
       {
         // do smoething
       }
       else 
       {
          // number is not available
       }
   }
}
Reply
#2

The problem with this code is that your else statement is going to be called every iteration(every time it is repeated) in foreach when the number does not match.

What is usually done when such loops are implemented are "return values" Usually - what happens is that when a value is returned by a function, all of the code that is later in the function is disregarded and the function stops running - allowing to move on with the next operation.

Therefore your code would look like this:
pawn Код:
if(strcmp(inputtext, "911") == 0)
{
   //do something if inputtext 911 (police, ems etc.)
   return 1;
}
else
{
   foreach(Player, i)
   {
       if(strcmp(PlayerInfo[i][pPhnumber], inputtext) == 0)
       {
         // do smoething
          return 1;
       }
   }
   // number not available
   return 0;
}
P.S. I am not too sure at what level for scripting you are - but if you didn't get it - I'll happily reword it for you if you could tell me the exact part you did not understand
Reply
#3

EDIT: My bad, i forgot that the ignorecase is optional.
Reply
#4

Thanks! But, if is not 911, then the // number not available is always called, not?
For e.g. 123 is a vaild phone number, do something, and do the // number not available?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)