I just compile the calc snippet with gcc (gcc version 4.0.0 20041026), and it simply gives the first number of the expression as the answer. I thought get_token() might not be appropriately advancing, but it will grab an operator followed by a number. It can operate correctly by placing each term of the expression in a separate round of input. However, * and / operators (as well as parens) are basically ignored.
Below is a sample usage cycle (as well as the gcc warnings, though you can ignore the returntype ... if you've not used gcc, it simply warns when you're not sending a return value to the OS as per POSIX, since the $? of ccalc is then highly unpredictable. (Portability note: int main() { return 0; } helps programs play nicely with standards-compliant OS'es.) Hope this helps, as I don't have time to debug it at present. Cheers!
I've got good news, and I've got bad news: The universe is merely a figment of my imagination. Now are you ready for the bad news?
33. [09/04 13:48] ~/src : keith -> gcc ccalc.c -o ccalc
ccalc.c:17: warning: conflicting types for built-in function 'exp'
ccalc.c: In function 'main':
ccalc.c:25: warning: return type of 'main' is not 'int'
...
36. [09/04 13:51] ~/src : keith -> ./ccalc
warning: this program uses gets(), which is unsafe.
enter expression: 5*4
answer is: 5
enter expression: *4
answer is: 5
enter expression: +4
answer is: 9
enter expression: -4
answer is: 5
enter expression: /4
answer is: 5
Below is a sample usage cycle (as well as the gcc warnings, though you can ignore the returntype ... if you've not used gcc, it simply warns when you're not sending a return value to the OS as per POSIX, since the $? of ccalc is then highly unpredictable. (Portability note: int main() { return 0; } helps programs play nicely with standards-compliant OS'es.) Hope this helps, as I don't have time to debug it at present. Cheers!
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
install python
}
open command/terminal
execute python
print (enter calculations)
Just thought I'd throw that out there
$> calc "expression"
would yield fantabulous results . . .
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
bc <<EOF
scale=6
$1
EOF
}