-
Structures & Comparing
I have a structure into which I have wrote a record from a binary file
e.g.
struct customer{
char type;
float balance;
};
I am wanting to check if the type is I or R.
Say customer_ptr is a pointer to the structure.
strcmp won't work:
strcmp(customer_ptr->type, 'I');
because of the type mismatch in parameters.
So what's the best way to do this?
I'm also having a problem with strcpy. I'm wanting to copy a float value into 'balance' in the structure.
strcpy(customer_ptr->balance, float);
Again a type mismatch.
What am I missing??
Kitten
-
> What am I missing?
That
char type;
float balance;
are not strings, so you need different comparison functions.
> strcmp(customer_ptr->type, 'I');
should be
if ( customer_ptr->type == 'I' ) {
// match
}
> strcpy(customer_ptr->balance, float);
should be
customer_ptr->balance = 123.45;