I am going through K&R C Answer Book and coding exercise4-3.c
there is a call for fmod library function which I thought was present in math.h but I am resulting an 'underfined reference to 'fmod'
the line in question is about 3 quarters the way down - just below the case '%': line
any clues what I am doing wrong.
gcc -o exercise4-3.exe exercise4-3.c
/tmp/ccOFQfVw.o: In function `main':
/tmp/ccOFQfVw.o(.text+0x169): undefined reference to `fmod'
gcc -v
Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]
Code:
#include <stdio.h>
#include <math.h> /* for atof() */
#include <ctype.h> /* for atof() */
#include <string.h>
#define MAXVAL 1000 /* maximum depth of val stack */
#define MAXOP 100 /* max size of operand or operator */
#define NUMBER '0' /* signal that a number was found */
#define BUFSIZE 100
int sp = 0; /* next free stack position */
double val[MAXVAL]; /* value stack */
int getop(char []);
void push(double);
double pop(void);
int getch(void);
void ungetch(int);
char buf[BUFSIZE]; /* buffer for ungetch */
int bufp = 0; /* next free positino in buf */
double atof(char s[]);
int i, sign;
/* reverse Polish calculator */
main()
{
int type;
double op2;
char s[MAXOP];
while ((type = getop(s)) != EOF) {
switch(type) {
case NUMBER:
push(atof(s));
break;
case '+':
push(pop() + pop());
break;
case '*':
push(pop() * pop());
break;
case '-':
op2 = pop();
push(pop() - op2);
break;
case '/':
op2 = pop();
if (op2 != 0.0)
push(pop() / op2);
else
printf("error: zero divisor\n");
break;
case '%':
op2 = pop();
if (op2 != 0.0)
push(fmod(pop(), op2));
else
printf("error: zero divisor\n");
break;
case '\n':
printf("\t%.8g\n", pop());
break;
default:
printf("error: unkown command %s\n", s);
break;
}
}
return 0;
}