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 


[C++]wierd thing happened

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

Joined: 04 Jul 2007
Posts: 74
Location: In that program you just downloaded

PostPosted: Fri Aug 24, 2007 1:40 pm    Post subject: [C++]wierd thing happened Reply with quote

ok well i was getting bored so i made this simple program but when i run no matter what i type it goes to the lose. can someone explain?
Code:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
   char name[20];
   char ser[20];
   cin>> name;
   cin>> ser;
   if (ser == name)
   {
      cout<<"win\n";
   }
   else
   {
      cout<<"lose\n";
   }
   return 0;
}
sorry if it was something stupid that i missed Embarassed
_________________


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

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Aug 24, 2007 1:55 pm    Post subject: Reply with quote

use strings instead of char's

Code:
#include <iostream>
#include <string>
using namespace std;

int main()
{
   string str;
   string str2;
   
   cin >> str;
   cin >> str2;
   
   if (str == str2)
   {
      cout << "Win!\n";
   }
   else if (str != str2)
   {
      cout << "Lose!\n";
   }

   system("pause");
   return 0;
}


works fine

Edit:

btw, u forgot to make hte text after ur script yellow Wink

_________________


Last edited by lurc on Fri Aug 24, 2007 1:59 pm; edited 2 times in total
Back to top
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Fri Aug 24, 2007 1:56 pm    Post subject: Re: [C++]wierd thing happened Reply with quote

merkark12 wrote:
ok well i was getting bored so i made this simple program but when i run no matter what i type it goes to the lose. can someone explain?
Code:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
   char name[20];
   char ser[20];
   cin>> name;
   cin>> ser;
   if (ser == name)
   {
      cout<<"win\n";
   }
   else
   {
      cout<<"lose\n";
   }
   return 0;
}
sorry if it was something stupid that i missed Embarassed


A character array is a pointer to an allocation in memory starting with the first letter and ending with a \0 character. Your comparing the memory addresses not the actual strings.

Either do what lurc suggested, or compare them letter for letter.

_________________
0x7A 0x61 0x72 0x74

TEAM RESURRECTiON
Back to top
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Fri Aug 24, 2007 7:57 pm    Post subject: Reply with quote

or strcmp
_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Aug 25, 2007 3:10 am    Post subject: Reply with quote

Code:
#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
   char name[20];
   char ser[20];
   cin>> name;
   cin>> ser;

   if (!strcmp(ser,name))
   {
      cout<<"win\n";
   }
   else
   {
      cout<<"lose\n";
   }
   return 0;
}
Back to top
View user's profile Send private message MSN Messenger
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