just a sample of what can be done

Dependencies:   mbed

PRN電卓プログラム

「プログラミング言語C (K&R本)」に出てくる例を元にした,RPN計算機です.

hp写真はイメージです

このプログラムは..

getop.cpp

Committer:
okano
Date:
2015-06-27
Revision:
5:3b9daee5f734
Parent:
3:4ef74510cc5b

File content as of revision 5:3b9daee5f734:

#include    "mbed.h"
#include    "calc.h"
#include    <ctype.h>

int getop( char s[] )
{
    int     i, c;

    while ( (s[ 0 ] = c = getch()) == ' ' || c == '\t' )
        ;

    s[ 1 ]  = '\0';

    if ( !isdigit( c ) && c != '.' )
        return c;

    i   = 0;

    if ( isdigit( c ) )
        while ( isdigit( s[ ++i ] = c = getch() ) )
            ;

    if ( c == '.' )
        while ( isdigit( s[ ++i ] = c = getch() ) )
            ;

    s[ i ]  = '\0';


    if ( c != EOF )
        ungetch( c );

    return NUMBER;
}