Xcode - Warning: Implicit declaration of function is invalid in C99
The function has to be declared before it's getting called. This could be done in various ways:
Write down the prototype in a header
Use this if the function shall be callable from several source files. Just write your prototypeint Fibonacci(int number);
down in a.h
file (e.g.myfunctions.h
) and then#include "myfunctions.h"
in the C code.Move the function before it's getting called the first time
This means, write down the functionint Fibonacci(int number){..}
before yourmain()
functionExplicitly declare the function before it's getting called the first time
This is the combination of the above flavors: type the prototype of the function in the C file before yourmain()
function
As an additional note: if the function int Fibonacci(int number)
shall only be used in the file where it's implemented, it shall be declared static
, so that it's only visible in that translation unit.
The compiler wants to know the function before it can use it
just declare the function before you call it
#include <stdio.h>int Fibonacci(int number); //now the compiler knows, what the signature looks like. this is all it needs for nowint main(int argc, const char * argv[]){ int input; printf("Please give me a number : "); scanf("%d", &input); getchar(); printf("The fibonacci number of %d is : %d", input, Fibonacci(input)); //!!!}/* main */int Fibonacci(int number){//…