Cześć
Mam problem, jak można przerobić ten program żeby można było wprowadzać liczby więcej niż jednocyfrowe ?
//#include <locale>
#include<stdlib.h>
#include"curses.h"
#include<locale.h>
struct stack_node
{
int data;
struct stack_node *next;
};
int main(void)
{
if(setlocale(LC_ALL,"")==NULL)
{
fprintf(stderr,"B³¹d inicjacji ustawieñ jêzykowych!\n");
return -1;
}
if(!initscr())
{
fprintf(stderr,"B³¹d inicjacji biblioteki curses!\n");
return -1;
}
printw("WprowadŸ wyra¿enie w Odwrotnej Notacji Polskiej\n");
(void)refresh();
printw("\nWynik dzia³ania to: %d.\n",calculate_rpn_expression());
(void)refresh();
getch();
if(endwin()==ERR)
{
fprintf(stderr,"B³¹d funkcji endwin()!\n");
return -1;
}
return 0;
}
struct stack_node *push(struct stack_node *top, int number)
{
struct stack_node *new_node = (struct stack_node *)
malloc(sizeof(struct stack_node));
if(new_node!=NULL)
{
new_node->data = number;
new_node->next = top;
top = new_node;
}
return top;
}
int pop(struct stack_node **top)
{
int result = -1;
if(*top)
{
result = (*top)->data;
struct stack_node *tmp = (*top)->next;
free(*top);
*top = tmp;
}
return result;
}
int calculate_rpn_expression(void)
{
int input = 0;
struct stack_node *top = NULL;
do
{
input = getch();
int first_argument=0, second_argument=0, result=0;
switch(input)
{
case '+':
result = pop(&top) + pop(&top);
top = push(top,result);
break;
case '-':
first_argument = pop(&top);
second_argument = pop(&top);
top = push(top,second_argument - first_argument);
break;
case '*':
result = pop(&top)*pop(&top);
top = push(top,result);
break;
default:
if(input>='0'&&input<='9')
top=push(top,input-'0');
}
}
while(input!='=');
return pop(&top);
}