In Dev-C++, I want to make a project to sort a table and that's why I brought the source files into my project. but when I want to compile my project, compiler gives me an error and it can't identify functions.
This is my first source file.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define LENGTH 5
I saved the first file in the computer as "Preprocessors.c".
The second source file :
void Selective_sorting(int Table[], int Length)
{
int *Temporary;
int Smallest_index;
for(register short int Outside = 0; Outside < Length; Outside++)
{
Smallest_index = Outside;
for(register short int Inside = (Outside + 1); Inside < Length; Inside++)
{
if(*(Table + Inside) < *(Table + Smallest_index))
Smallest_index = Inside;
}
Temporary = (int*) malloc(sizeof(int));
if(!Temporary)
{
printf("An error occurred while allocating memory.\n");
exit(1);
}
*Temporary = *(Table + Smallest_index);
*(Table + Smallest_index) = *(Table + Outside);
*(Table + Outside) = *(Table + Smallest_index);
free(Temporary);
}
}
I saved the second source file in the computer as "Selective_func.c".
And the third source code to run the program :
int main()
{
int table[5] = {9, 7, 6, 5, 3};
Selective_sorting(table, 5);
for(register short int Counter = 0; Counter < 5; Counter++)
printf("%d\n", *(table + Counter));
return 0;
}
I saved the third source file in the computer as "Main_func.c".
And I brought the source files into my project and when I compiled the project, this error occurred:
You're not including files correctly.
Your main file needs to include the headers it needs: like stdlib.h and stdio.h but also a header that defines void Selective_sorting(int Table[], int Length);
.
Then your implementation file should also include that same header with the void Selective_sorting(int Table[], int Length);
prototype + any header files needed for things it uses (e.g. stdio.h because you use printf()
).
Basically you should always remember that any C file (either .c or .h) you want to compile doesn't know about any function, variable or type (except for system built-in ones) if you don't include the header file that defines it.