user1050632 user1050632 - 4 months ago 60
C Question

Error: "expected '(' before string constant"

Working on computing the geometric mean of values in an array

The function should compute the geo mean correctly, but i'm getting a weird error message

#include <stdio.h>
#include <stdint.h>
#include <math.h>

extern "C"

double geomean(double myarray[], int count) ////error here, expected '(' before string constant
double geomean = 1;
double root = (1/(double)count);
int i;
for(i = 0; i < count; i++)
geomean = geomean * myarray[i];
geomean = pow(geomean, root);
return geomean;


extern "C" is not valid C (it's only valid in C++). Just remove it if you're working in pure C.