1
#include <stdio.h>


int singleFib(int x,int a,int b);
int multiFib(int x);


void main(){
int n,i;
printf("How much?\n");
scanf("%d",&n);

for(i=0;i<n;i++){
    printf("%5d. number:   %d   -  %d \n",i+1,multiFib(i),singleFib(i,1,1));


}

getch();
return 0;

}

int multiFib(int x){

if (x<2){
    return 1;
}
else{
    return multiFib(x-2)+multiFib(x-1);
}


int singleFib(int x,int a,int b){

if (x<2){
    return 1;
}
else{

    return singleFib( x-1, b,(a+b));
}

}
}

The error is in

singleFib(i,1,1) in `printf`

Whyis that problem?how can i solve that problem? i am using codeblocks

Codeblocks\Fiberonacci\main.c|14|undefined reference to `singleFib'| The error is that.how can i solve?

4
  • 3
    You need to start indenting your code properly. Also, it's called Fibonacci, not Fiberonacci. Commented Nov 16, 2013 at 16:28
  • 2
    Welcome to SO! Can you not make a smaller example that fails in the same way? The question will be easier to answer, more useful to others, and you might just find the answer yourself this way. Commented Nov 16, 2013 at 16:28
  • Nested function is a GCC extension which some gcc-compatible compilers like icc do support. It's not portable. Commented Nov 16, 2013 at 16:34
  • This code is a good (or merely bad) example where proper indentation would have made the error immediately obvious. Commented Nov 16, 2013 at 16:34

4 Answers 4

6
  1. You're missing a close bracket } at the end of your multiFib function.

  2. You have an extra close bracket } at the end of your singleFib function.

  3. The function main should have return type int.

Sign up to request clarification or add additional context in comments.

Comments

1

The { and } in multiFib and singleFib are mixed up, singleFib is declared inside multiFib:

int multiFib(int x){

    if (x<2){
        return 1;
    }
    else{
        return multiFib(x-2)+multiFib(x-1);
    }


    /*************************************/
    int singleFib(int x,int a,int b) {

        if (x<2){
            return 1;
        }
        else{

            return singleFib( x-1, b,(a+b));
        }
    }

    /*************************************/
}

it works in gcc, since it's an nonstandard nested functions extension, but the function will not be accessible outside multiFib.

Comments

0

Seems like there is a mismatch in the braces of the function definition

Comments

0

You're missing a closing bracket for multiFib, but have one that you don't need after singleFib.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.