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 


char with +,- to int

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

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sat Apr 17, 2010 1:51 am    Post subject: char with +,- to int Reply with quote

Heey

Ive beent trying almost everything i can think off

but if uve got:

Code:
char x[10] = 2+2;


how can i make a int x = y? I know how to do the numbers, but with the + i keep failing.

I want to know the answer of x, but since u can do + in a char, ive to convert to int, but it goes wrong

tried:
atoi
strstream
using lexical_cast:
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1888
Location: Canada

PostPosted: Sat Apr 17, 2010 2:33 am    Post subject: This post has 1 review(s) Reply with quote

http://en.wikipedia.org/wiki/Shunting_yard_algorithm -> http://en.wikipedia.org/wiki/Reverse_Polish_notation
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1858

PostPosted: Sat Apr 17, 2010 5:31 am    Post subject: Reply with quote

can you give an example of what you're trying to do ?

are you trying to convert the int on the right to a string and then assigning it to the char array ?
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Apr 17, 2010 5:36 am    Post subject: Reply with quote

Slugsnack wrote:
can you give an example of what you're trying to do ?

are you trying to convert the int on the right to a string and then assigning it to the char array ?

I think he wants to parse a string like "2 + 5 * 2" and get the resulting number in an int.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1858

PostPosted: Sat Apr 17, 2010 7:24 am    Post subject: Reply with quote

can use regex or pattern matching i guess
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sat Apr 17, 2010 9:55 am    Post subject: Reply with quote

Im trying to make it that ( in a calculator) people can typ, 2+2+2+(2 * (3/4)) and there is a answer,

but for the EDIT box where ppl can typ the numbers in i use CHAR, so if some1 typs 2+3*5, ive to convert it to int
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1888
Location: Canada

PostPosted: Sat Apr 17, 2010 2:28 pm    Post subject: Reply with quote

NoMercy wrote:
Im trying to make it that ( in a calculator) people can typ, 2+2+2+(2 * (3/4)) and there is a answer,

but for the EDIT box where ppl can typ the numbers in i use CHAR, so if some1 typs 2+3*5, ive to convert it to int


If it wasn't obvious from my first post, you have to use the shunting yard algorithm to parse the string into reverse polish notation onto a stack, and then use a reverse polish notation calculator to solve it.

This is the best way. You can't just 'cast to an int' and have it magically solve the equation for you (well, you could, but you'd have to use operator overloading and what I said in the first part Wink).
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Mon Apr 19, 2010 12:33 am    Post subject: Reply with quote

thanks flyte,

It took me a few hours to write all those functions, but i think ive got it working now
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