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++] [Help] sprintf not working I guess

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Mattraks
How do I cheat?
Reputation: 0

Joined: 21 Oct 2007
Posts: 0
Location: IRAQ!

PostPosted: Mon Sep 01, 2008 11:39 am    Post subject: [C++] [Help] sprintf not working I guess Reply with quote

Well, I'm going to make a bot for a certain channel on IRC and so far, it isn't working how I want it to. The code I'm having problems with is:

Code:
char nick[] = "";
char tempnick[] = "";
char identify[] = "";
char tempidentify[] = "";
int isregistered = 1;
char idleident[] = "";
char tempidleuser[] = "";
char tempidlepass[] = "";

int main() {
   std::cout << "Enter a nick: ";
   std::cin >> tempnick;
   sprintf(nick, "NICK %s\r\n", tempnick);
   std::cout << "Enter the pass with nickserv(0 if not registered): ";
   std::cin >> tempidentify;
   sprintf(identify, "PRIVMSG nickserv IDENTIFY %s\r\n", tempidentify);
   if (strcmp(tempidentify, "0") == 0) {
      isregistered = 0;
   }
   std::cout << "Enter your idlerpg username(cAsE sEnSaTiVe): ";
   std::cin >> tempidleuser;
   std::cout << "Enter your idlerpg password(cAsE sEnSaTiVe): ";
   std::cin >> tempidlepass;
   sprintf(idleident, "PRIVMSG idlebot login %s %s\r\n", tempidleuser, tempidlepass);
   printf("%s = NICK\n %s = identify\n %s = idleident\n", nick, identify, idleident);
   Sleep(10000);
   exit(0);


That outputs:
Quote:
Enter a nick: nick
Enter the pass with nickserv(0 if not registered): passwithnickserv
Enter your idlerpg username(cAsE sEnSaTiVe): idleuser
Enter your idlerpg password(cAsE sEnSaTiVe): idlepass
NIPRPRIVMSG idlebot login RIVMSG idlebot login RIVMSG idlebot login RIVMSG i IVM
SG idlebot login RIVMSG idlebot login RIVMSG idlebot login RIVMSG i
= NICK
PRPRIVMSG idlebot login RIVMSG idlebot login RIVMSG idlebot login RIVMSG i IVMS
G idlebot login RIVMSG idlebot login RIVMSG idlebot login RIVMSG i
= identify
PRIVMSG idlebot login RIVMSG idlebot login RIVMSG idlebot login RIVMSG i IVMSG
idlebot login RIVMSG idlebot login RIVMSG idlebot login RIVMSG i
= idleident


I filled out what it asks and that's what happens.

Does anyone know why its happening and/or can tell me how to fix it? Thanks.

_________________
FOR ALLAH!
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Mon Sep 01, 2008 12:53 pm    Post subject: Reply with quote

Personally, with so many cout/cin's i would just use namespace std;

Code:
   sprintf(nick, "NICK %s\r\n", tempnick);


Nothing is stored in
Code:
nick
yet

Why switch between cout/sprintf?



Code:
   sprintf(identify, "PRIVMSG nickserv IDENTIFY %s\r\n", tempidentify);


Nothing is stored in identify yet either.



On second thought, I'm not familiar enough with sprintf() to be positive but if nothing else consider this a bump for you.

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Sep 01, 2008 1:04 pm    Post subject: Reply with quote

Code:
char nick[] = "";


just do this

Code:
char nick[256];


Then at the start of your code (or when you need a clean buffer)

Code:
memset(nick, 0,255);

_________________
Back to top
View user's profile Send private message
Mattraks
How do I cheat?
Reputation: 0

Joined: 21 Oct 2007
Posts: 0
Location: IRAQ!

PostPosted: Mon Sep 01, 2008 1:04 pm    Post subject: Reply with quote

manc wrote:
Why switch between cout/sprintf?

cout just prints out a message.

sprintf sets the destination (first parameter) to what you have for the second parameter and then sets the %'s to what you have for the third, fourth, fifth, etc. to the value of those. Similar to printf in the way of the %'s.

@blankrider: Thanks, that worked

_________________
FOR ALLAH!


Last edited by Mattraks on Mon Sep 01, 2008 1:08 pm; edited 1 time in total
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Sep 01, 2008 1:08 pm    Post subject: Reply with quote

Also, i suggest using scanf http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html

If you are going to use function s like sprintf and printf you should go 100% instead of mixing libraries and including unnecessary code

_________________
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Sep 01, 2008 1:21 pm    Post subject: Reply with quote

Main problem is that you are not allocating memory for those strings, and it is not being allocated locally. You need to make it an array of given size or allocate it dynamically (malloc).
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Mon Sep 01, 2008 5:26 pm    Post subject: Reply with quote

you cannot do

char tempidleuser[] = "";

etc.. it has to be allocated yah..

like char tempidleuser[2] = "";

that will be a array for 2 characters..

you think using tempidleuser[]

will give you any size you want? and that is the case it does work.. when you do tempidleuser[] in a function.. you can *Copy* another array and it will work but you just copied it but the allocation still happened but you just don't see it..

Code:

int main(int a, char*b[]) {
    playerChat("test test 123 testing, oh yah up the ...");
    return 0;
}

void playerChat(char chat[]) {
    printf("chat = %s", chat);
}

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Sep 01, 2008 7:44 pm    Post subject: Reply with quote

Add

using namespace std;

So you can just do cout instead of std::cout.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Sep 01, 2008 8:25 pm    Post subject: Reply with quote

_void_ wrote:
Add

using namespace std;

So you can just do cout instead of std::cout.


So we see who is a lazy coder.
I Don't recommend doing what _void_ told you to do. It's pointless and stupid for only using a mere 2 functions. Especially when the application is small.

_________________
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