just a sample of what can be done

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers getop.cpp Source File

getop.cpp

00001 #include    "mbed.h"
00002 #include    "calc.h"
00003 #include    <ctype.h>
00004 
00005 int getop( char s[] )
00006 {
00007     int     i, c;
00008 
00009     while ( (s[ 0 ] = c = getch()) == ' ' || c == '\t' )
00010         ;
00011 
00012     s[ 1 ]  = '\0';
00013 
00014     if ( !isdigit( c ) && c != '.' )
00015         return c;
00016 
00017     i   = 0;
00018 
00019     if ( isdigit( c ) )
00020         while ( isdigit( s[ ++i ] = c = getch() ) )
00021             ;
00022 
00023     if ( c == '.' )
00024         while ( isdigit( s[ ++i ] = c = getch() ) )
00025             ;
00026 
00027     s[ i ]  = '\0';
00028 
00029 
00030     if ( c != EOF )
00031         ungetch( c );
00032 
00033     return NUMBER;
00034 }