Advertisement

if statment

Started by November 06, 2000 10:01 PM
3 comments, last by slightlywhacked 24 years, 2 months ago
I have this if statment if (temp != "Nigel") { strcpy(sp1truck5, temp); infile.get(sp1truck5url, 50); infile.ignore(80, ''\n''); infile.get(temp, 50); infile.ignore(80, ''\n''); } Now..I ran the debugger to this if statment..and the variable temp = "Nigel" ... the exact spelling and case. but the if statement is still going through.. I cant see why it is. The conditions arnt met..so it should run.. That is the right statement for somthing not equalling somthing right
BAHcows go moomoos go cow
Use strcmp instead.

=======================================
Better to reign in hell than serve in heaven.
John Milton, Paradise Lost
Advertisement
What is the type on temp? Is it some type of string class? If it is a char it should have given at least a warning. If it is a char pointer then you compared the address in temp to the address of the string "Nigel". With C++ it is hard to guess data types. I''m also confused why you would copy temp to sp1truck and then overlay it with the infile.get. Assuming common mistakes in C I would say you should have done a strcmp in the if statement and reversed the parameters in the strcpy, but then you overlay temp as well so I really don''t know why you did the strcpy unless the get routine is actually a put routine.
Keys to success: Ability, ambition and opportunity.
temp is a string

Its kind of hard to explain why im replacing it later...but Ill try.. i have a file..it reads

Lude
truck #1
Truck #2
truck #3
truck #4
Nigel
truck #1
Truck #2
truck #3
truck #4

at some point... Ludes trucks stop, and Nigles trucks start..Now..I need to detect that ... so i have a variable detect if the next line down is Nigel.. and if it is skip all hte steps to load in more trucks under lude
right now whats going on is
Ludes trucks are:
truck #1
Truck #2
truck #3
truck #4
Nigel
truck #1
Truck #2
truck #3
truck #4


it dosnt detect Nigel.. thats why im using hte if statment, and using temp to read the next line down
BAHcows go moomoos go cow
Try this:

#define THE_SAME 0

if ( strcmp(temp, "Nigel") != THE_SAME )
{
strcpy(sp1truck5, temp);
infile.get(sp1truck5url, 50);
infile.ignore(80, ''\n'');
infile.get(temp, 50);
infile.ignore(80, ''\n'');
}

the return value is kind of confusing (for me it''s the opposite) so when checking to see if the strings are the same you might be confused, so I just used a define statement which makes the code easier to understand!

-------------------------------
"Mind your own damn business!!!" - Gladiator

..-=gLaDiAtOr=-..

This topic is closed to new replies.

Advertisement