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++ Char-by-Char in String

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

Joined: 02 Nov 2008
Posts: 494
Location: Canada eh?

PostPosted: Sun Mar 22, 2009 11:20 pm    Post subject: C++ Char-by-Char in String Reply with quote

Any idea why this wouldn't work?



Code:
void Arithmetic(string number)
{
   string temp = "";
   for(int i = 0; i < number.length(); i++)
   {
      if(number[i] == '+')
      {
         WriteLn(temp);
         temp = "";
         Arithmetic(number.substr(i+1,number.length()-(i+1));
      }
      temp += number[i];
   }
}


This doesn't work I can't figure it out o.0 (which is odd)



Any ideas? In theory it loops through all characters and if its a + then it calls a new one, yet it messes up.

_________________
Back to top
View user's profile Send private message Send e-mail
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Mar 23, 2009 12:44 am    Post subject: Reply with quote

F5 would like a word with you
Back to top
View user's profile Send private message
mStorm
Expert Cheater
Reputation: 0

Joined: 21 Feb 2009
Posts: 107

PostPosted: Mon Mar 23, 2009 12:04 pm    Post subject: Reply with quote

I don't exactly see what you are trying to accomplish, there is probably an easier way than recursive function calling...
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Mon Mar 23, 2009 1:47 pm    Post subject: Reply with quote

try number.length() - 1 instead of number.length()
_________________
Back to top
View user's profile Send private message Send e-mail
mStorm
Expert Cheater
Reputation: 0

Joined: 21 Feb 2009
Posts: 107

PostPosted: Mon Mar 23, 2009 3:15 pm    Post subject: Reply with quote

This might work for you:

Code:

void Arithmetic(string number)
{
   for (int i=1; i <=(int)number.length();i++)
   {
      if (number.substr(i, 1)=="+")
      {
         
         cout << number.substr(0, i) << endl;
         Arithmetic(number.substr(i+1, number.length() - (i+1)));
         return;
      }
   }
   cout << number << endl;
}
Back to top
View user's profile Send private message
AlbanainRetard
Master Cheater
Reputation: 0

Joined: 02 Nov 2008
Posts: 494
Location: Canada eh?

PostPosted: Mon Mar 23, 2009 4:33 pm    Post subject: Reply with quote

@Kitterz Length-1 Wouldn't work It just means I am going less.

@mStorm, thanks I guess next time I should use substr through all the code

@slovach Debugging really does not help.

_________________
Back to top
View user's profile Send private message Send e-mail
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Mon Mar 23, 2009 5:51 pm    Post subject: Reply with quote

@albanian.. debugging DOES help..next time use fucking stoi() to do this shit..and listen to kitterz.. o0

regards BanMe

_________________
don't +rep me..i do not wish to have "status" or "recognition" from you or anyone.. thank you.
Back to top
View user's profile Send private message MSN Messenger
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Mon Mar 23, 2009 6:42 pm    Post subject: Reply with quote

try Arithmetic(number.substr(i+1,number.length()-(i+2));

im not too sure about it. You make the code very confusing.

I suggest that you do it another way.

_________________
Back to top
View user's profile Send private message Send e-mail
AlbanainRetard
Master Cheater
Reputation: 0

Joined: 02 Nov 2008
Posts: 494
Location: Canada eh?

PostPosted: Mon Mar 23, 2009 6:57 pm    Post subject: Reply with quote

kitterz wrote:
try Arithmetic(number.substr(i+1,number.length()-(i+2));

im not too sure about it. You make the code very confusing.

I suggest that you do it another way.


Well I got it working. Anywho I would need to make it go from another direction on list or opperations due to it saying: 1+2 = Add 1, 2.

_________________
Back to top
View user's profile Send private message Send e-mail
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Mon Mar 23, 2009 7:22 pm    Post subject: Reply with quote

AlbanainRetard wrote:
kitterz wrote:
try Arithmetic(number.substr(i+1,number.length()-(i+2));

im not too sure about it. You make the code very confusing.

I suggest that you do it another way.


Well I got it working. Anywho I would need to make it go from another direction on list or opperations due to it saying: 1+2 = Add 1, 2.


why don't you try using strtok()

_________________
Back to top
View user's profile Send private message Send e-mail
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