int main( int argc, char* argv) {
	char* infix = "5 *  ( 2 + 10 )  /  ( 8 + 2 ) ";
	printf("This is the infix %s\n", infix);
	char* postfix = in2post(infix);
	printf("This is the post fix %s\n", postfix);
	int result = postEval(postfix);
	printf("This is the answer to the equation %d\n", result);	
	return 0;
}
Exemple #2
0
/**Functions**/
int main(int argc, char *argv[]){
    /*argument detection*/
    if(argc == 3){
        cInput = argv[1];
        cOutput = argv[2];
    }
    else
        printf("Proceed with default setting...\n");

    /*Open input/output file*/
    fpInput = fpOutput = NULL;
    if((fpInput = fopen(cInput, "r")) == NULL){
        printf("Error: failed to open input file.\n");
        exit(0);
    }
    if((fpOutput = fopen(cOutput, "w")) == NULL){
        printf("Error: failed to open output file.\n");
        exit(1);
    }

    /*Algorithm begins here*/
    int iHowMany = 0;
    char input[SIZE], output[SIZE];
    fscanf(fpInput, " %d\n", &iHowMany);
    for(int i=1; i<=iHowMany; i++){
        fgets(input, SIZE, fpInput);
        input[strlen(input)-1]='\0'; //neglect the newline character
        in2post(input, output);
        fprintf(fpOutput, "\n");
    }

    /*Program ended: close files*/
    fclose(fpInput);
    fclose(fpOutput);
    fpInput = fpOutput = NULL;
    return 0;
}