james-collinss-macbook-pro:chap2 jamescollins$ gcc atof.c calculator.c -o calculator.o
atof.c: In function atof:
atof.c:15: error: called object val is not a function
got the following error messages from terminal when i tried to compile a program from a book on c.
i have a question on compiling what should i call a function which the book calls
atof should i compile it as:
i also don't understand the error message:
here is the function file which i called atof.c
and here is the main program (should i call this calculator.c ?)
any help would be appreciated.
atof.c: In function atof:
atof.c:15: error: called object val is not a function
got the following error messages from terminal when i tried to compile a program from a book on c.
i have a question on compiling what should i call a function which the book calls
atof should i compile it as:
Code:
atof.c calculator.c -o calculator.o
i also don't understand the error message:
Code:
atof.c:15: error: called object val is not a function
here is the function file which i called atof.c
Code:
#include <ctype.h>
/* atof: convert string s to double used with calculator */
double atof(char s[])
{
double val, power;
int i, sign;
for (i = 0; isspace(s[i]); i++) /* skip white space */
;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-')
i++;
for (val = 0.0; isdigit(s[i]); i++)
val = 10.0 * val (s[i] - '0');
if (s[i] == '.')
++i;
for (power = 1.0; isdigit(s[i]); i++) {
val = 10.0 * val + (s[i] - '0');
power *= 10.0;
}
return sign * val / power;
}
and here is the main program (should i call this calculator.c ?)
Code:
#include <stdio.h>
#define MAXLINE 100
/* rudimentary calculator using atof.c function */
main()
{
double sum, atof(char []);
char line[MAXLINE];
int getline(char line[], int max);
sum = 0;
while (getline(line, MAXLINE) > 0)
printf("\t%g\n", sum += atof(line));
return 0;
}
any help would be appreciated.