Reputation: 35
I am creating project in arduino. In C. How can I check if return char is existing in my array?
This is how I want it.
char n[20];
char *adminName[] = {"Jane", "Joe", "James"};
I want to return true
if (n)
is in my list.
Upvotes: 1
Views: 4753
Reputation: 389
you have to use the strcmp() that check the diff between 2 char *
char n[20];
char *adminName[] = {"Jane", "Joe", "James"};
int i;
i = 0;
while (admminName[i])
{
if (strcmp(n, adminName[i]) == 0)
return (true);
i++;
}
return (false);
Upvotes: 0
Reputation: 426
There are many built in functions are there for this. why cant you use those functions rather than checking manually by loops?
Upvotes: 0
Reputation: 155600
Loop over array indices and use strcmp(n, adminName[i]) == 0
to test whether the string n
is part of the array.
Upvotes: 3