我最近在学校(不到2个月前)开始进行C / C编程,所以我不知道我在做什么 .
从我的代码我收到这些错误消息:
错误LNK2019:未解析的外部符号“double __cdecl MyRand(double,double)”(?MyRand @@ YANNN @ Z)在函数_main错误中引用LNK2019:未解析的外部符号“int __cdecl love_code(void)”(?love_code @@ YAHXZ)在函数_main致命错误LNK1120中引用:2个未解析的外部
我在这个网站上看到了类似的问题,但是我提供的解决方案都没有 . 我该如何解决这个错误?
如果有人想知道,图片提供原始代码和输出应该是什么样子 .
我的代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
double length (double x1, double y1, double z1, double x2, double y2, double z2);
double squares (double x);
double MyRand ( double a, double b);
int love_code();
int main()
{
char name[20], parent[15];
strcpy_s(name, "Susan McLeod");
strcpy_s(parent, "Bernice McLeod");
int i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13;
i2 = name[0], i3 = name[1], i4 = name[2], i5 = name[3], i12 = name[4], i13 = name[5];
i6 =parent[0], i7=parent[1], i8=parent[2], i9=parent[3], i10=parent[4], i11=parent[5];
cout << "The ASCII code of [" << name << "] are " <<'['<< i2 <<']'<<'['<< i3 <<']'<<'['<< i4 <<']'<<'['<< i5 <<']'<<'['<< i12 <<']'<<'['<< i13 <<']'<< endl;
cout << "The ASCII code of [" << parent << "] are " <<'['<< i6 <<']'<<'['<< i7 <<']'<<'['<< i8 <<']'<<'[' << i9 <<']'<<'['<< i10 <<']'<<'['<< i11 <<']'<< endl;
int j, love, txtcode, shift, len;
FILE *f1, *f2, *f3;
char txt [5000];
love = love_code();
cout << "The love code is [" << love << ']' << endl;
srand (love);
fopen_s(&f1, "letter.txt", "r");
fopen_s(&f2, "hw_04_code.txt", "w");
fopen_s(&f3, "hw_03_code.txt", "w");
if (f1 == NULL) printf ("Cannot open file - letter.txt\n");
if (f2 == NULL) printf ("Cannot open file - hw_04_code.txt\n");
if (f3 == NULL) printf ("Cannot open file - hw_03_code.txt\n");
j = 0;
while (fscanf_s (f1, "%c", &txt [j]) !=EOF)
{
shift = (int) (MyRand (0, 6));
txtcode = txt [j] << shift;
fprintf (f3, "%10d\n", txt [j]);
//fprintf (f2, "%10d, %10d\n", txtcode, shift)
fprintf (f2, "%10d\n", txtcode);
j++;
}
txt [j] = '\0';
len = strlen (txt);
printf ("The total number of characters are %d\n", len);
fclose (f1);
fclose (f2);
fclose (f3);
return (0);
}
//return random number between a and b
double MyRand ( double a, double b);
{
return ((b - a + 1) * rand() / (double) RAND_MAX + a);
}
1 回答
此语句不会创建函数,而是创建另一个函数声明
由于编译器无法找到声明的函数,因此会给出错误 . 删除 - >
;
在双MyRand ( double a, double b)
结尾处,编译器不会抱怨未解析的MyRand(double,double)
external .