In this case
strlen()
is the wrong option. As Rick points out,
strlen()
expects a C style character string. Now you could, of course, alter
custIDs
variable to add a nul char at the end, e.g.
char custIDs[11] = { 'A', 'B', 'D', 'E', 'F', 'G', 'H' 'I', 'J', 0};
but that just abuses the idea of what a custID might be and how C strings work. A better solution would be to use a
#define
to capture the number of customers in the "database" e.g.
#include <stdio.h>
#define CUST_SIZE 10
int main()
{
int i, j;
char custIDs[CUST_SIZE] = { 'A' ... 'J' };
for(i = 0; i < CUST_SIZE; ++i)
{
}
for( j = 0; j < CUST_SIZE; ++j )
{
}
}
Note that we really don't need separate variables for each
for
loop, since the two loops are independent of each other. Better yet, if you have C99 or later (confusingly, perhaps, that's C11) you an use a for looped scoped variable, e.g.
for(size_t i = 0; i < CUST_SIZE < ++i)