-
comparing struct members
struct anything{
char name[10];
int age;
int Nat_ins_num[6];
};
struct crooks{
char name[10];
int age;
int Nat_ins_num[6];
};
int main()
{
using the above structs as an example, comparing the name
member i know can be done like
srtcmp(anything.name, crooks.name)
but i'm not quite sure how to compare integers, because we are told
that comparison operators can't be used with struct members i.e
if(anything.age == crooks.age) //illegal ( or is it? )
if you can give me some examples on how to do this,
the more examples that you can show about comparing the struct members either char, int, or float.
will help a great deal
T.I.A
;)
-
You are correct, you can use structure members as like other variables.
if(anything.age == crooks.age) //illegal ( or is it? )
yes it is.
-
Thank you Unregistered, i had started to think that i was speaking in double dutch in this forum,
The usual reply is "I can't see your logic"
Just to clarify. ( for the use of anyone that see's this thread)
In presume these are correct.
if(anything.age > crooks.age) // is this legal?
if(anything.age != crooks.age) // is this?
A quick yes or no from the guru's will help clarify this Q :rolleyes:
Cheers group;)
-
Think about it..... maybe even try it....
you are comparing an int with an int so do you think that is legal?!
-
> A quick yes or no from the guru's will help clarify this Q
Legal - yes
Anything which compiles without warnings is at least syntactially valid.
Whether its the right thing to do is another matter - the compiler won't help you here.