Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


StrCmp

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
AIva1110
Advanced Cheater
Reputation: 0

Joined: 16 Sep 2009
Posts: 56
Location: The Void

PostPosted: Wed Sep 23, 2009 6:19 am    Post subject: StrCmp Reply with quote

if(!strcmp(flight[t].from, from) && !strcmp(flight[t].to, to))

Anybody knows why statements in if are not returning true in this statement, since all parameters are correct and checked before execution.

Strcmp returns 0, in c anything but 0 is true, that is why ! statements are used.

_________________



Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Sep 23, 2009 6:26 am    Post subject: Reply with quote

we can't check until you give us more code. i suggest you debug it. the computer can not be wrong. if it's returning a result you are not expecting it must be an error on your side
Back to top
View user's profile Send private message
AIva1110
Advanced Cheater
Reputation: 0

Joined: 16 Sep 2009
Posts: 56
Location: The Void

PostPosted: Wed Sep 23, 2009 6:46 am    Post subject: Reply with quote

Problem is im in library atm so i cant use olly here, there isnt much point in posting anything else because functions are independent, only 2 parameters are passed to this function declaration is : int match(char *from,char *to)
after that i check parameters with printf() to see if they were passed correctly, they are. After this follows if statement. Here, main part of the function checks excluded. I checked what's t and what is passed from array as well.
Code:

int match(char *from,char *to)
{
   
   register int t;

   for(t=f_pos-1; t>-1; t--)
   {
      
      if(!(strcmp(flight[t].from, from) && strcmp(flight[t].to, to)))
      {
         
         return flight[t].distance;
      }
   }   return 0; /*Not found*/
}

_________________



Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Sep 23, 2009 7:10 am    Post subject: Reply with quote

okay before the strcmps, add a MessageBox which display all 4 compared strings. I'm guessing what's happening is that your match function is returning 0 ?

i'm also guessing 'flight' is extern, i don't see it anywhere in your function ?
Back to top
View user's profile Send private message
AIva1110
Advanced Cheater
Reputation: 0

Joined: 16 Sep 2009
Posts: 56
Location: The Void

PostPosted: Wed Sep 23, 2009 7:22 am    Post subject: Reply with quote

Flight is an array of structures, I'm comparing it's member .from with parameter "from" which is passed to function. I checked everything that's being compared, it prints correct strings. Now I tried printing return value of StrCmp and it just crashes the program, probably because I don't know how to print it lol. Any ideas how to print return value correctly? google search didn't yield much results.
_________________



Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Sep 23, 2009 7:37 am    Post subject: Reply with quote

Code:
printf ("Return was %d\n", result);


or wcstol()
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Wed Sep 23, 2009 7:39 am    Post subject: Reply with quote

What if one of the string returns a non-zero value? which means, the strings are different and the result of x & 0 = 0, then when you NOT it then you'll get 1 even though only one of the strings is different than the other.

You should do:
if (strcmp(..) == 0 && strcmp(..) == 0)
......
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Sep 23, 2009 7:54 am    Post subject: Reply with quote

yes, his code in the first post was correct. i did not notice that it was different in the code example he gave though
Back to top
View user's profile Send private message
AIva1110
Advanced Cheater
Reputation: 0

Joined: 16 Sep 2009
Posts: 56
Location: The Void

PostPosted: Wed Sep 23, 2009 8:26 am    Post subject: Reply with quote

That code i gave has a mistake i left it doing experiments, assume code from first post is used.

I tried testing return value of strcmp using printf() as slugsnack suggested and it returned wrong result, then I checked flight[t].from against from passed to a function and flight[t].from has string from the bottom of database when it was supposed to have it from the top, the odd thing is that top and bottom entries match and i didn't notice this until now. When checking second string program crashed because they were incorrect...now it's fixed. Thanks for help everyone.

_________________



Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites