OpenVPN
Data Structures | Typedefs | Functions | Variables
calculator.c File Reference
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for calculator.c:

Go to the source code of this file.

Data Structures

struct  OperatorFunction
 

Typedefs

typedef int(* BinaryOperator) (int a, int b)
 
typedef struct OperatorFunction OperatorFunction
 

Functions

BinaryOperator find_operator_function_by_string (const size_t number_of_operator_functions, const OperatorFunction *const operator_functions, const char *const operator_string)
 
int perform_operation (int number_of_arguments, char *arguments[], const size_t number_of_operator_functions, const OperatorFunction *const operator_functions, int *const number_of_intermediate_values, int **const intermediate_values, int *const error_occurred)
 
static int add (int a, int b)
 
static int subtract (int a, int b)
 
static int multiply (int a, int b)
 
static int divide (int a, int b)
 
int main (int argc, char *argv[])
 

Variables

static OperatorFunction operator_function_map []
 

Typedef Documentation

◆ BinaryOperator

typedef int(* BinaryOperator) (int a, int b)

Definition at line 88 of file calculator.c.

◆ OperatorFunction

Function Documentation

◆ add()

static int add ( int  a,
int  b 
)
static

Definition at line 122 of file calculator.c.

◆ divide()

static int divide ( int  a,
int  b 
)
static

Definition at line 134 of file calculator.c.

◆ find_operator_function_by_string()

BinaryOperator find_operator_function_by_string ( const size_t  number_of_operator_functions,
const OperatorFunction *const  operator_functions,
const char *const  operator_string 
)

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 258 of file calculator.c.

References free, and perform_operation().

◆ multiply()

static int multiply ( int  a,
int  b 
)
static

Definition at line 130 of file calculator.c.

◆ perform_operation()

int perform_operation ( int  number_of_arguments,
char *  arguments[],
const size_t  number_of_operator_functions,
const OperatorFunction *const  operator_functions,
int *const  number_of_intermediate_values,
int **const  intermediate_values,
int *const  error_occurred 
)

◆ subtract()

static int subtract ( int  a,
int  b 
)
static

Definition at line 126 of file calculator.c.

Variable Documentation

◆ operator_function_map

OperatorFunction operator_function_map[]
static
Initial value:
= {
{"+", add},
{"-", subtract},
{"*", multiply},
{"/", divide},
}
static int add(int a, int b)
Definition: calculator.c:122
static int divide(int a, int b)
Definition: calculator.c:134
static int subtract(int a, int b)
Definition: calculator.c:126
static int multiply(int a, int b)
Definition: calculator.c:130

Definition at line 115 of file calculator.c.