bug fixes
This commit is contained in:
		
							
								
								
									
										10
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.c
									
									
									
									
									
								
							@@ -17,17 +17,17 @@ char* manipulate_str(double input);
 | 
			
		||||
 | 
			
		||||
int main(const int argc, char *argv[]) {
 | 
			
		||||
    const double res = calculate(parse_input(argc, argv));
 | 
			
		||||
    //manipulate string by cutting of trailing zeros
 | 
			
		||||
    char* final_string = manipulate_str(res);
 | 
			
		||||
 | 
			
		||||
    char* final_string = manipulate_str(res);
 | 
			
		||||
    printf("%s %s %s = %s\n", argv[1], argv[2], argv[3], final_string);
 | 
			
		||||
 | 
			
		||||
    free(final_string);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CalcStr parse_input(const int n, char *argv[]) {
 | 
			
		||||
    if (n < 4) {
 | 
			
		||||
        perror("Insuficient arguments (3 are required), exiting");
 | 
			
		||||
        fprintf(stderr, "Insuficient arguments (3 are required), exiting...\n");
 | 
			
		||||
        exit(EXIT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -63,7 +63,7 @@ double calculate(const CalcStr calc) {
 | 
			
		||||
            return calc.first + calc.second;
 | 
			
		||||
        case '-':
 | 
			
		||||
            return calc.first - calc.second;
 | 
			
		||||
        case '*':
 | 
			
		||||
        case 'x':
 | 
			
		||||
            return calc.first * calc.second;
 | 
			
		||||
        case '/':
 | 
			
		||||
            return calc.first / calc.second;
 | 
			
		||||
@@ -77,7 +77,7 @@ double calculate(const CalcStr calc) {
 | 
			
		||||
 | 
			
		||||
            return r;
 | 
			
		||||
        default:
 | 
			
		||||
            perror("Invalid operand type");
 | 
			
		||||
            fprintf(stderr, "Invalid operand type\n");
 | 
			
		||||
            exit(EXIT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user