heidi boynww
heidi boynww

Reputation: 35

undefined reference to function error in c

#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?

Upvotes: 1

Views: 24303

Answers (4)

user1129665
user1129665

Reputation:

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.

Upvotes: 1

Eutherpy
Eutherpy

Reputation: 4581

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

Upvotes: 0

aks
aks

Reputation: 167

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

Upvotes: 0

godel9
godel9

Reputation: 7390

  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.

Upvotes: 6

Related Questions