编写了一个学生信息管理系统运行出错,如下,
1>pointer.obj : error LNK2019: 无法解析的外部符号 "struct student * __cdecl find_student(int)" (?find_student@@YAPAUstudent@@H@Z),该符号在函数 "void __cdecl search(void)" (?search@@YAXXZ) 中被引用
1>D:\cc\pointer\Debug\pointer.exe : fatal error LNK1120: 1 个无法解析的外部命令
网上说这是缺少相应的文件,不知道缺少哪些文件?授人以鱼不如授人以渔,能弄懂最好不过了。谢谢
这个错误很常见,你代码列出来看看呗
// pointer.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
#include
#define NAME 20
struct student
{
char name[NAME+1];
int id;
int age;
char sex[6];// man or woman 最大为6个字符
int score;
struct student *next;
};
struct student *first=NULL;
struct student *find_student(int id);
void insert(void);//增添学生信息
void search(void);//查找
void update(void);//修改更新
void print(void);//打印
int _tmain(int argc, _TCHAR* argv[])
{
char opt;
for ( ; ;)
{
printf("please enter the operation:");
scanf("%c",&opt);
while (getchar()!='\n')
;
switch (opt)
{
case 'i': insert();break;
case 's': search();break;
case 'u': update();break;
case 'p': print();break;
case 'q': return 0;
default : printf("enter the right operation!");
}
printf("\n");
}
}
struct student *find_studnet(int id)//输入学号,返回空指针或者对应的结构体
{
struct student *p;
for (p = first; p != NULL && id > p->id; p = p->next)
;
if (p != NULL && id == p->id)
return p;
return NULL;
}
void insert(void)
{
struct student *now;
struct student *past;
struct student *new_one;
new_one = (struct student *)malloc(sizeof(struct student));
if (new_one == NULL)
{
printf("the system is full now.");
return;
}
printf("enter new id");
scanf("%d",&new_one->id);
for (now = first, past = NULL;
now != NULL && new_one->id > now->id;
past = now, now = now->next)
;
if (now != NULL && new_one->id == now->id )
{
printf("student already exit.\n");
free(new_one);
return;
}
printf("enter the student name:");
scanf("%c",&new_one->name);//scanf() 和readline
printf("enter the age:");
scanf("%d",&new_one->age);
printf("enter sex:");
scanf("%c",&new_one->sex);
printf("enter score:");
scanf("%c",&new_one->score);
new_one->next = now;
if (past == NULL)
first = new_one;
else
past->next = new_one;
}
void search(void)
{
int id;
struct student *p;
printf("enter the student id:");
scanf("%d",&id);
p = find_student(id);
if (p != NULL)
printf("the information of the student: %s\t %s\t %d \n",p->name, p->sex, p->age);
else
printf("Found NO student in!");
}
void update(void)
{
int id, n; //n是学号修改的差值,例如学号15135,实际为15130,可以用n = -5来修改
struct student *p;
printf("enter the student id:");
scanf("%d",&id);
p = find_student(id);
if (p != NULL)
{
printf("enter the change value:");
scanf("%d",&n);
p->id +=n;
}
else
printf("Found NO student in!\n");
}
void print(void)
{
struct student *p;
printf("\nname \tid \tsex\t\n");
for (p = first; p != NULL; p = p->next)
printf("%s\t %d\t %s ",p->name, p->id, p->sex);
}
find_student这个函数没有申明或者函数原型和你的调用不符合,检查你的search的代码
我找到错误了,student写错了。。。谢谢热心回答
这种错误只有一个原因:
有东西只声明未实现,根据这个去检查就好了。
函数 find_student定义的时候定义成了 find_studnet。引用时候成了 find_student。所以说找不到。