I have to make a program where the user enters 3 char characters which ends up being a number, an operator, and another number. (ex. 5,+,6)
The 5 and 6 are char numbers. How do I add them together? or convert them into int?
I have to make a program where the user enters 3 char characters which ends up being a number, an operator, and another number. (ex. 5,+,6)
The 5 and 6 are char numbers. How do I add them together? or convert them into int?
Here's some commands you may want to look up and learn for this:
- fgets
- sscanf
- strtol (or atoi)
- switch
Look at the bottom of this page:
http://206.251.36.107/programming/stdin_buffer.mhtml
where I give an example of a "foolproof" function for getting a single number. You can modify that to do what you want.
You can use switch to evaluate the arithmetic operation, eg, "case (+), case(-)" etc.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge