Indent your code properly, e.g.,
Code:
bool Search(char *a, int size, char *which) // Search element
{
Ptr b = a;
int flag = 0;
for (int i = 0; i <size; i++)
{
if (b[i] == toupper(*which))
{
flag = 1;
return true;
}
if (flag == 1)
{
return true;
}
else
{
return false;
}
}
}
Now, it is clear that your code is equivalent to:
Code:
bool Search(char *a, int size, char *which) // Search element
{
Ptr b = a;
for (int i = 0; i <size; i++)
{
if (b[i] == toupper(*which))
{
return true;
}
return false;
}
}
Hence the loop only iterates once, at most.