Hi. I wrote a calculator that calculates the given expression (eg, 2 +3 +4-3-1), it works only if you type expression and press ctrl-d, what i have to do to display the result after pressing enter
Here's the code:
#include <stdio.h>
int main()
{
printf("give expression \n");
char expression;
int x,y;
scanf("%d",&x);
while (scanf("%c %d",&expression,&y) !=EOF)
{
if (expression == '+')
x+=y;
if (expression == '-')
x-=y;
}
printf("\n %d\n",x);
return 0;
}
I thought to change
while (scanf("%c %d",&wyrazenie,&y) !=EOF)
to
while (scanf("%c %d",&wyrazenie,&y) !='\0')
but then the result does not show.
Sorry for my English.