Tedd OKANO
/
RPN_calc__based_on_K_and_R
just a sample of what can be done
PRN電卓プログラム
「プログラミング言語C (K&R本)」に出てくる例を元にした,RPN計算機です.
写真はイメージです
このプログラムは..
- 『mbed祭り 2015@初夏の東銀座』の親睦会で「RPN」と題して行ったLT(LightningTalk)でのデモ・プログラムです.
- mbed LPC1768,mbed LPC1114FN28で実行できることを確認しています(たぶん他のプラットフォームでも動きます)
- プレゼンスライドを置いておきます
getch.cpp@5:3b9daee5f734, 2015-06-27 (annotated)
- Committer:
- okano
- Date:
- Sat Jun 27 01:29:21 2015 +0000
- Revision:
- 5:3b9daee5f734
- Parent:
- 4:b4c8aee2ecad
functions "power" and "drop" are added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 2:0e96f4495b43 | 1 | #include "mbed.h" |
okano | 2:0e96f4495b43 | 2 | #include "calc.h" |
okano | 3:4ef74510cc5b | 3 | #include <ctype.h> |
okano | 2:0e96f4495b43 | 4 | |
okano | 2:0e96f4495b43 | 5 | #define BUFSIZE 100 |
okano | 2:0e96f4495b43 | 6 | |
okano | 2:0e96f4495b43 | 7 | char buf[ BUFSIZE ]; |
okano | 2:0e96f4495b43 | 8 | int bufp = 0; |
okano | 2:0e96f4495b43 | 9 | |
okano | 2:0e96f4495b43 | 10 | int getch( void ) |
okano | 2:0e96f4495b43 | 11 | { |
okano | 2:0e96f4495b43 | 12 | #if 1 |
okano | 2:0e96f4495b43 | 13 | int c; |
okano | 2:0e96f4495b43 | 14 | c = (bufp > 0) ? buf[ --bufp ] : getchar(); |
okano | 4:b4c8aee2ecad | 15 | if ( isprint( c ) && c != ' ' ) |
okano | 3:4ef74510cc5b | 16 | printf( "[%c]\r\n", c ); |
okano | 2:0e96f4495b43 | 17 | return c; |
okano | 2:0e96f4495b43 | 18 | #else |
okano | 2:0e96f4495b43 | 19 | return (bufp > 0) ? buf[ --bufp ] : getchar(); |
okano | 2:0e96f4495b43 | 20 | #endif |
okano | 2:0e96f4495b43 | 21 | } |
okano | 2:0e96f4495b43 | 22 | |
okano | 2:0e96f4495b43 | 23 | |
okano | 2:0e96f4495b43 | 24 | void ungetch( int c ) |
okano | 2:0e96f4495b43 | 25 | { |
okano | 2:0e96f4495b43 | 26 | if ( bufp >= BUFSIZE ) |
okano | 2:0e96f4495b43 | 27 | printf( "ungetch: too many characters\n" ); |
okano | 2:0e96f4495b43 | 28 | else |
okano | 2:0e96f4495b43 | 29 | buf[ bufp++ ] = c; |
okano | 2:0e96f4495b43 | 30 | } |
okano | 2:0e96f4495b43 | 31 |