#include <stdio.h>
#include <stdlib.h>

FILE * input;
int errorFlag = 0;

int isDigit(int c) 
{
	/*do{
		c = getc(input);
		printf("%c", c); 
	}
	while (c == ' ' || c == '\t' || c == '\n');
	ungetc(c, input);*/ 
	if (c >= '0' && c <= '9')
		return 1;
	else
		return 0;
}

int op()
{
  int a;

        do
	a = getc(input);
	while (a == ' ' || a == '\t' || a == '\n');
	ungetc(a, input);
	if (a == '+')
		return 1;
	else if (a == '-')
		return 0; 
}

int oper(int a, int b, char c) 
{
	if (c == '+') 
		return a + b; 
	if (c == '-') 
		return a - b; 
}

int main(){
	FILE *input, *output;

	int num1 = 0;
	int num2 = 0;
	char op = '\0';

	int value;
	
	int varValue[26];
	char varName;
	int result;

	char c,d; 
	int cnt = 0; 
	int cnt2 = 0; 

	input = fopen("input.txt", "r");
	output = fopen("output.txt", "w"); 

    //No input file error
	if (input == NULL){
		printf("Missing input file.\n");
		return;
	}
	
	
	
	
	else { 
		do { 
				c = getc(input); 

			//printf("%c\n",c);
			if (c == ' ' || c == '\t' || c == '\n')
            continue;

			if (isDigit(c)) {
				cnt2 += 1;
				if (cnt == 0) {
					d = c-48;  
					cnt = 1;
				}
				else { 
					
					// call operator function 
					d = oper(d, c-48, op);  
				}  
			} 
			else {
				if (c == ';') { 
					printf("%d\n", d); 
					cnt = 0; 
					cnt2 = 0; 
				}
				else {
					op = c; 
				}  
			} 
		} 
		while (c != EOF); 
	} 
	
	
	if (fscanf(input, "%d", &num2) == EOF)
		printf("Empty input file. \n");
		
	
	fclose(input);
	fclose(output);
	
	system("pause");
	return 0;
}
