Advertisement

Simple IF problem

Started by May 08, 2000 04:31 PM
3 comments, last by jLeslie 24 years, 7 months ago
Can anyone tell me how to get these if statements to work? FILE *myfile = fopen(strFileName, "r"); char Chunk_Name[80]; while(fscanf(myfile, "%s" , Chunk_Name)) { if (Chunk_Name == "Bone") LoadBone(); if (Chunk_Name == "Chan") LoadChannel(); if (Chunk_Name == "Join") LoadJoint(); if (Chunk_Name == "PolH") LoadPolyhedron(); } Thanks
why not use a switch statement?

or bung some elses in there
if (Chunk_Name == "Bone")
LoadBone();
else if (Chunk_Name == "Chan")
LoadChannel();
else if (Chunk_Name == "Join")
LoadJoint();
else if (Chunk_Name == "PolH")
LoadPolyhedron();


then they are all part of one statement...
maybe...

Check out my shadows page
and send me some feedback
Check out my shadows page and send me some feedback
Advertisement
if(!strcmp(Chunk_Name, "Bone"))
LoadBone();

aig
aig
Dont try to use == with char* it will only give you grief, as you are experiencing now - use strcmp() to compare two strings for equality. When you do == with two char* the compiler will actually check the pointers to the first characters in the strings for equality not the actual value of the strings

B
Makes sense

This topic is closed to new replies.

Advertisement