Home > Back-end >  Why can't contains header files or in the main function calls to functions that have been decla
Why can't contains header files or in the main function calls to functions that have been decla

Time:10-02

Below is saved as a diceroll. H header file
Extern int roll_count;
Int roll_n_dice (int dice, int sides);
Created called diceroll. C source file
In the source file defines the roll_n function,
Then in the main function in the source file contains a header file
#include
#include
#include
# include "diceroll. H"
Compile error, display an undefined roll_n function,
If add # include "diceroll. C", that it is no meaning to this header file does not,

CodePudding user response:

And see if it is in diceroll. C file forgot to include inside diceroll. H, if not, see if the function name wrong,
Compile error, display an undefined roll_n function, roll_n function and the roll_n_dice above is the same here? Is it your shorthand, or an error that quote?

CodePudding user response:

Check the extern here? The defined in other places if no may cause problems

CodePudding user response:

This is diceroll. C head
# include "diceroll. H"
#include
#include
In the source file also defines roll_n_dice function
Int roll_n_dice (int dice, int sides)
Below is saved as a diceroll. H header file
Extern int roll_count;
Int roll_n_dice (int dice, int sides);
Then in the main function in the source file contains a header file
#include
#include
#include
# include "diceroll. H"
Compile error, display an undefined roll_n_dice function,
  • Related