c - Xcode - Warning: Implicit declaration of function is invalid in C99 -


getting warning : implicit declaration of function 'fibonacci' invalid in c99. what's wrong?

#include <stdio.h>  int main(int argc, const char * argv[]) {     int input;     printf("please give me number : ");     scanf("%d", &input);     getchar();     printf("the fibonacci number of %d : %d", input, fibonacci(input)); //!!!  }/* main */  int fibonacci(int number) {     if(number<=1){         return number;     }else{         int f = 0;         int vv = 0;         int v = 1;         (int i=2; i<=getal; i++) {             f = vv+v;             vv = v;             v = f;         }         return f;     } }/*fibonacci*/ 

the function has declared before it's getting called. done in various ways:

  • write down prototype in header
    use if function shall callable several source files. write prototype
    int fibonacci(int number);
    down in .h file (e.g. myfunctions.h) , #include "myfunctions.h" in c code.

  • move function before it's getting called first time
    means, write down function
    int fibonacci(int number){..}
    before main() function

  • explicitly declare function before it's getting called first time
    combination of above flavors: type prototype of function in c file before main() function

as additional note: if function int fibonacci(int number) shall used in file it's implemented, shall declared static, it's visible in translation unit.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -