/* Get an RPN expression from the keyboard.
* Accepts q as indictation that user wants to quit.
* Skips over invalid characters.
* Normal end of expression is '='.
*/
#include <stdio.h>
#include <ctype.h>
#include "inputter.h"
#include "stack.h"
char* get_next_token(void)
{
char next_ch[1000];
int i=0;
char* n;
do
{
*next_ch = getchar();
if (tolower((int)*next_ch) == 'q')
{
// User wants to quit.
break;
}
if ((*next_ch == '\n'))
{
break;
}
if (isdigit(*next_ch) ||
(*next_ch == '+') ||
(*next_ch == '-') ||
(*next_ch == '*') ||
(*next_ch == '/') ||
(*next_ch == '=') )
{
printf("entered is %s\n", next_ch);
++*next_ch;
i++;
}
if(tolower((int)*next_ch) == 'c')
{
clear_stack();
}
if(tolower((int)*next_ch) == 'p')
{
pop();
}
if(tolower((int)*next_ch) == 't')
{
int m =(int)*next_ch * -1;
*next_ch = m;
++*next_ch;
i++;
}
// if ((*next_ch == '+') && (*next_ch == 'p') &&
// (*next_ch == '-') && (*next_ch == 't') &&
// (*next_ch == '*') && (*next_ch == 'c') &&
// (*next_ch == '/') && (*next_ch == '=') &&
// (isdigit(*next_ch)) )
// {
// continue;
// }
// else
// {
// printf("Wrong input\n");
// *n='q';
// break;
// }
n=next_ch;
} while (*next_ch!= ' ');
//n = 0; // Provide null terminator.
return n;
}
If you could please email me what you think I should do to xxxx@yahoo.com.
This post has been edited by Martyn.Rae: 10 April 2010 - 09:28 PM
Reason for edit:: Emial removed

New Topic/Question
Reply
MultiQuote







|