【发布时间】:2025-12-16 15:45:01
【问题描述】:
在 Dev-C++ 中,我想创建一个项目来对表格进行排序,这就是我将源文件带入我的项目的原因。但是当我想编译我的项目时,编译器给了我一个错误,它无法识别函数。
这是我的第一个源文件。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define LENGTH 5
我将计算机中的第一个文件保存为“Preprocessors.c”。
第二个源文件:
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);
}
}
我在计算机中将第二个源文件保存为“Selective_func.c”。
以及运行程序的第三个源代码:
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;
}
我将第三个源文件保存在计算机中为“Main_func.c”。
我把源文件带进我的项目,当我编译项目时,出现了这个错误:
【问题讨论】:
-
使用这些包含的函数,包含必须对 .c 文件可见。所以你不应该有一些神秘的“Preprocessors.c”——那个文件什么也没做。相反,您应该在函数所在的 .c 文件中包含一个 .h 文件。此外,代码本身存在多个问题,但这是另一回事。