-
Help needed!
I want to look in a big array for three signs in a row
i use this code to do it but it doesnt seems to work.
It is supposed to jump out of the while loop when it finds "12D"
It jumps out of the while loop as soon as it find a "D"
Help please...
Code:
while (Barcode[date0] != 1 && Barcode[date1] != 2 && Barcode[date2] != 'D')
{
date0++; date1++; date2++;
}
-
When you && things together all of them have to be true for the loop to continue. If one of the conditionals is false, then the while loop will end. So, if either
Barcode[date0] != 1
or
Barcode[date1] != 2
or
Barcode[date2] != 'D'
is false, then the while loop will fail.
If you || things together, then the only way the conditional is false is if ALL of them are false.
-
Also.
What you have is a character array. What you're comparing to is integers. 1 and 2. They are characters as well, just represented in ascii value. So by the time you're finding the 'D', the other two elements I'm sure aren't ascii 1 and 2 which aren't standard characters.
You want this:
Code:
while (!(Barcode[date0] == '1' && Barcode[date1] == '2' && Barcode[date2] == 'D'))
{
date0++; date1++; date2++;
}
//or if you wish: while (Barcode[date0] != '1' || Barcode[date1] != '2' || Barcode[date2] != 'D')