注册 登录
编程论坛 C语言论坛

哪位高手帮忙看一下这问题该怎么解决,谢谢!

kr0 发布于 2020-06-28 17:09, 2225 次点击
#include<stdio.h>
#define SIZE  5
void show_array(const double ar[], int n);
void mult_array(double ar[], int n, double mult);
int main(void)
{
    double dip[SIZE] = { 20.0, 17.66, 8.2, 15.3, 22.22 };

    printf("The original dip array:\n");
    show_array(dip, SIZE);
    mult_array(dip, SIZE, 2.5);
    printf("The dip array after calling mult_array():\n");
    show_array(dip, SIZE);
    return 0;
}
void show_array(double a[], int n)
{
    int i = 0;
    for (i = 0; i < SIZE; i++)
        printf("%8.3f", a[i]);
    printf("\n");
}
void mult_array(double a[], int n, double mult)
{
    int i = 0;
    for (i = 0; i < SIZE; i++)
        a[i] *= mult;
        
}


错误    1    error LNK2019: 无法解析的外部符号 "void __cdecl show_array(double const * const,int)" (?show_array@@YAXQBNH@Z),该符号在函数 _main 中被引用    D:\新建文件夹 (2)cpj\10.14 arf\10.14 arf\10.14 arf.obj



我有好几个代码写成来都是这种情况,我是书上的代码敲得,可是就是会有这种报错,新手不懂,求解,谢谢!
7 回复
#2
ditg2020-06-28 17:25
void show_array(const double ar[], int n);

const去掉再试试
#3
rjsp2020-06-28 19:25
说个题外话,从“void __cdecl show_array(double const * const,int)" (?show_array@@YAXQBNH@Z)”来看,你用的C++编译吧?
C是C,C++是C++,两个不同的语言,尽量不要用C++去学C。
#4
ditg2020-06-28 22:51
问个事,你是不是把程序全放一块了?
#5
八画小子2020-07-01 12:51
以下是引用rjsp在2020-6-28 19:25:18的发言:

说个题外话,从“void __cdecl show_array(double const * const,int)" (?show_array@@YAXQBNH@Z)”来看,你用的C++编译吧?
C是C,C++是C++,两个不同的语言,尽量不要用C++去学C。

可能是用VC++写的,没法用C编译器。
#6
八画小子2020-07-01 12:54
程序代码:
void show_array(const double ar[], int n);

void show_array(double a[], int n)
{
    int i = 0;
    for (i = 0; i < SIZE; i++)
        printf("%8.3f", a[i]);
    printf("\n");
}


函数声明和函数定义中函数头不一致。如果是在C编译器中,会告诉你不一致的信息。在C++编译器中会提示你找不到。
#7
rjsp2020-07-01 13:33
以下是引用八画小子在2020-7-1 12:51:02的发言:
可能是用VC++写的,没法用C编译器。

将源文件扩展名改为 *.c
#8
八画小子2020-07-01 15:57
以下是引用rjsp在2020-7-1 13:33:28的发言:


将源文件扩展名改为 *.c

这个确实没有试过,回头看看。一直以为VS IDE编译C/C++代码时,都用的是C++编译器。
1