# Can someone point out where I went wrong?

This is a discussion on Can someone point out where I went wrong? within the C Programming forums, part of the General Programming Boards category; Code: // Fiboncacci Test--------------------------------- int n; int* fib; printf("\nFibonacci test 1: enter an integer\n"); scanf("%d",&n); fib = a(n); printf("fib(%d) = ...

1. ## Can someone point out where I went wrong?

Code:
```  // Fiboncacci Test---------------------------------
int n;
int* fib;

printf("\nFibonacci test 1: enter an integer\n");
scanf("%d",&n);

fib = a(n);
printf("fib(%d) = ", n);

for(int i = 0; i < n; ++i)
{
printf("%d ", fib[i]);
}```
Code:
```int a(const int c)
{
int i;
int b[c];

for(i = 2; i<c; ++i)
{
b[0] = 0;
b[1] = 1;
b[i] = b[i-1] + bi-2];
}
return b[i];
}```
I have no idea where I went wrong, I have check through my course book and still I am stuck, any help appreciated! Thank you.

2. Set b[0] and b[1] before your loop.

Also, in line 11, you're missing the opening square bracket in b[i-2].

3. Originally Posted by TheBigH
Set b[0] and b[1] before your loop.

Also, in line 11, you're missing the opening square bracket in b[i-2].
Hi, thanks for your input the missing bracket is the copying i miss it. When I take b[0] and b[1] out it still does not show, apparently it shows some weird number

4. Do you even know what data type your fib variable is supposed to be? You declare it as a pointer to an integer, then you set it to an integer with the function "a", then you treat it as an array of ints in your printf.

5. return b[i]; /* likely off by one error; also called fence post error */

Tim S.

6. Yeah I got guys, thank you. I use the int* b = malloc(....) and it works, maybe should learn dynamic array again.