I would like to know how make the division between declaration and definition. I read few related with this topic question but for now I can do this only in basic funtion. The problem is when I try to declare constant global variable in header file and I want use this constant in the function which have declaration in the same place but definition in other files. I have 2 files with .c extension and one with .h extension.
File main_lib.h consist:
#ifndef _MAIN_LIB_H_
#define _MAIN_LIB_H_
const int N_POINTS=10;
struct Point{
int x;
int y;
};
void fill_random(struct Point points[], int n);
void closest(struct Point points[], int n, struct Point* p);
#endif /* _MAIN_LIB_H_ */
File main_lib.c consist:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "main_lib.h"
void fill_random(struct Point points[], int n){
...
}
void closest(struct Point points[], int n, struct Point* p){
...
}
And the last file named main.c consist:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "main_lib.h"
int main()
{
srand(time(0));
struct Point random_points[N_POINTS];
struct Point *p;
p=&random_points[0];
fill_random(p,N_POINTS);
closest(p,N_POINTS,p);
return 0;
}
The question is how to correct this code to run it without error status. Thanks a lot for any help.