C code: Getting a "cannot convert double to double*" error

Hey all!

This is C code, but I thought it similar enough to C++ to post it here...

Anyhow, I'm getting 4 compiler errors, that are all telling me "cannot covert double to double*", but I'm stumped as to WHY it's telling me that.

I'll post the snippits it's complaining about:

From the header file/
1
2
3
4
5
6
7
8
9
10
11
12
13
#define NUM_INPUTS 15

void print_array_dbl(double , int);

//definition from further down in the file:

void print_array_dbl(double Array[], int C) {
	int i = 0;
	
        for(i; i < C+1; ++i) {
	printf("%lf", Array[i]);
	}
}


Then from the .c file/

1
2
3
4
5
6
7
        //From variable declarations
        int capacity = NUM_INPUTS - 1;


        // Display the inputs in a nice format
	printf("Input values:\n");
	print_array_dbl(inputs[NUM_INPUTS], capacity);


When compiling this, it throws an error for this function. Anyone help me with why?

Thanks,
-Andrew
There is a huge difference between handing your friend a cookie and handing your friend a box of cookies. Your friend only accepts boxes, not individual cookies.

Pass the array, not the value in the array at index NUM_INPUTS (which is probably out of bounds anyway).
Ooooooooh *facepalm* my god, how did I do that...

Thank you!

One more quick question, lets say for that print feature, I need to print out a "[" before element one, a comma between each element, and a "]" after the final element, how would I go about doing this?

I tried this:
1
2
3
4
5
6
7
8
9
void print_array_dbl(double Array[], int C) {
	printf("[ ");
	int i = 0;
	for(i; i < C+1; ++i) {
		printf("%lf", Array[i]);
		printf(", ");
	}
	printf(" ] \n");
}


but that gives me errors... quite a few actually. Like:
"missing ";" before type"
"i": undeclared identifier"
"i":undeclared identifier"

I'm used to using cout (C++), not printf, so can anyone explain what's so wrong about this?

for example, in C++, out could just say cout << "blah blah text " << value << "more text. \n", and it would work fine...
Last edited on
What standard of C are you compiling with? Try using -std=c99 or -std=c11 on the commandline, and if those don't work and you can't update your compiler (or if you're using VC++) then you need to look up C90's syntax. In particular, variable declarations have to happen before executable code, so you have to declare i before that printf.
Topic archived. No new replies allowed.