求大神指导
GLXT.obj : error LNK2001: unresolved external symbol _head
Debug/GLXT.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
什么原因啊 代码? zltzlt 发表于 2019-12-22 11:54
代码?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct wokertype
{
char wokerbir; /*出生日期*/
char workno; /*工号*/
char worname; /*姓名*/
char workwage; /*工资*/
struct wokertype *pNext;
}WOKE,*PWOKE;
PWOKE pHead = NULL;
PWOKE pNew = NULL;
size_t iCount = 0;
void head();
void Menu();
void Quit();
void Add_Information();
void Delete_Information();
void Search_Information();
int main()
{
Menu();
return 0;
}
int MenuSelect();
typedef enum Menu
{
Exit,Add,Delete,Search
}MENU;
void Menu()
{
switch (MenuSelect()) //菜单选择
{
case Exit: //退出程序
system("wok");
head();
Quit(); //退出或返回主菜单
break;
case Add: //添加信息
system("wok");
Add_Information();
Quit();
break;
case Delete: //删除信息
system("wok");
Delete_Information();
Quit();
break;
case Search: //查询信息
system("wok");
Search_Information();
Quit();
break;
default:
printf("选择错误,退出!");
Quit();
break;
}
}
int MenuSelect()
{
char c;
do
{
system("wok");
head();
printf("\t\t\t\t ═══════════════=════════\n");
printf("\t\t\t\t│ 信息管理系统 │\n");
printf("\t\t\t\t ════════=═══════════════\n");
printf("\t\t\t\t ┌────────────────-─────-┐\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 1. 查询员工 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 2. 添加员工 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 3. 删除员工 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 4. 退出程序 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t └──────────────────────┘\n");
printf("\t\t\t\t\t\t请您选择(1-4):");
c = getchar();
}
while (c < '1' || c > '4');
return c - '1';
}
void Quit()
{
char tc;
int i;
printf("\n\t ");
for (i = 0; i < 50; i++)
{
printf("* ");
}
printf("\n\n\t\t\t\t要返回登录界面按任意键\t\t退出程序请按Esc键\n");
tc = getchar();
if (tc == 27) //esc键按下
{
exit(0);
}
//重新进入主菜单
Menu();
}
void Add_Information()
{
system("WOK");
head();
pNew = (PWOKE)malloc(sizeof(WOKE));
printf("\t\t\t\t\t\t添加员工信息:\n\n\n\n\t\t\t\t\t\t工号: ");
scanf("%s", pNew->workno);
printf("\n\t\t\t\t\t\t姓名: ");
scanf("%s", pNew->worname);
printf("\n\t\t\t\t\t\t工资: ");
scanf("%s", pNew->workwage);
printf("\n\t\t\t\t\t\t出生日期: ");
scanf("%s", pNew->wokerbir);
pNew = NULL;
iCount++;
}
void Delete_Information()
{
char ID;
char sc;
PWOKE pCurrnode = pHead; //指向头结点
head();
printf("\t\t\t\t\t\t删除信息:\n\n\n");
printf("\t\t\t\t\t\t请输入员工工号:");
scanf("%s", ID);
//遍历信息
while (pCurrnode->pNext != NULL) //遍历输出所有
{
if (strcmp(pCurrnode->pNext->workno, ID) == 0)
{
//信息库里面有要删除的信息
printf("\n\n\n\t\t\t\t\t要删除的员工信息...\n\n");
printf("\n\n\t\t\t\t\t工号\t姓名\t工资\t出生日期\n\n");
printf("\t\t\t\t\t %s\t %s\t %s\t %s\t\n",pCurrnode->pNext->workno,
pCurrnode->pNext->worname,pCurrnode->pNext->workwage,pCurrnode->pNext->wokerbir);
printf("\n\n\n\t\t\t\t\t是否删除该信息(y/Enter):");
sc = getchar();
if (sc == 'y' || sc == 'Y' || sc == 13)
{
PWOKE pTemp = pCurrnode->pNext;
pCurrnode->pNext = pTemp->pNext;
free(pTemp);
iCount--;
printf("\n\n\n\t\t\t\t\t删除成功...\n\n");
return;
}
else{
printf("\n\n\n\t\t\t\t\t删除失败...\n\n");
return;
}
}
pCurrnode = pCurrnode->pNext;
}
printf("\n\n\n\n\t\t\t\t\t 没有找到要删除的信息......\n\n");
}
void Search_Information()
{
char ID;
PWOKE pCurrnode;
head();
printf("\t\t\t\t\t\t查询信息:\n\n\n");
printf("\t\t\t\t\t\t请输入员工工号:");
scanf("%s", ID);
pCurrnode = pHead->pNext;
while (pCurrnode != NULL)
{
if (strcmp(pCurrnode->workno, ID) == 0)
{
printf("\n\n\n\t\t\t\t\t要查询的学生信息...\n\n");
printf("\n\n\t\t\t\t\t工号\t姓名\t工资\t出生日期\n\n");
printf("\t\t\t\t\t %s\t %s\t %s\t %s\t\n", pCurrnode->workno,
pCurrnode->worname, pCurrnode->workwage,pCurrnode->wokerbir);
return;
}
pCurrnode = pCurrnode->pNext;
}
pCurrnode = NULL;
printf("\n\n\n\n\t\t\t\t\t 没有找到要查询的学生信息......\n\n");
}
少了head()函数的代码。
superbe 发表于 2019-12-22 13:28
少了head()函数的代码。
添加不了数据,能帮我再看看吗? 本帖最后由 superbe 于 2019-12-22 22:48 编辑
是在windows下还是linux下运行的呢。这是我在windows+visual studio中测试的代码,可以正常运行。如果在linux下需要修改。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
typedef struct wokertype
{
char wokerbir; /*出生日期*/
char workno; /*工号*/
char worname; /*姓名*/
char workwage; /*工资*/
struct wokertype *pNext;
}WOKE, *PWOKE;
PWOKE pHead = NULL;
PWOKE pNew = NULL;
size_t iCount = 0;
//void head();
void Menu();
void Quit();
void Add_Information();
void Delete_Information();
void Search_Information();
void free_memory();//释放malloc分配的内存
int main()
{
Menu();
free_memory();
return 0;
}
int MenuSelect();
typedef enum Menu
{
Search, Add, Delete, Exit
}MENU;
void Menu()
{
switch (MenuSelect()) //菜单选择
{
case Exit: //退出程序
//system("wok");
//head();
//Quit();
printf("\n\t\t 程序结束.\n");
return;
case Add: //添加信息
//system("wok");
Add_Information();
Quit(); //退出或返回主菜单
break;
case Delete: //删除信息
//system("wok");
Delete_Information();
Quit();
break;
case Search: //查询信息
//system("wok");
Search_Information();
Quit();
break;
default:
;
}
}
int MenuSelect()
{
char c;
//system("wok");
//head();
printf("\t\t ═══════════════=════════ \n");
printf("\t\t│ 信息管理系统 │\n");
printf("\t\t ════════=═══════════════ \n");
printf("\t\t┌────────────────-─────-┐\n");
printf("\t\t│ │\n");
printf("\t\t│ 1. 查询员工 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 2. 添加员工 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 3. 删除员工 │\n");
printf("\t\t│ │\n");
printf("\t\t│ 4. 退出程序 │\n");
printf("\t\t│ │\n");
printf("\t\t│ │\n");
printf("\t\t└──────────────────────┘\n");
printf("\t\t 请您选择(1-4):");
while ((c = getchar()) < '1' || c > '4'){
printf("\n\t\t 选择错误,请选择1-4:");
if (c == '\n') continue;
while(getchar() != '\n');
}
while (getchar() != '\n');
return c - '1';
}
void Quit()
{
char tc;
int i;
printf("\n\t");
for (i = 0; i < 66; i++)
{
printf("*");
}
printf("\n\t\t 要返回登录界面按任意键\t\t退出程序请按Esc键\n\n");
tc = getch();
if (tc == 27) //esc键按下
{
printf("\n\t\t 程序结束.\n");
exit(0);
}
//重新进入主菜单
Menu();
}
void Add_Information()
{
PWOKE p;
//system("WOK");
//head();
if (pHead == NULL) {
pHead = (PWOKE)malloc(sizeof(WOKE));
pHead->pNext = NULL;
}
pNew = (PWOKE)malloc(sizeof(WOKE));
printf("\n\t\t 添加员工信息:\n");
printf("\n\t\t 工号: ");
scanf("%s", pNew->workno);
printf("\n\t\t 姓名: ");
scanf("%s", pNew->worname);
printf("\n\t\t 工资: ");
scanf("%s", pNew->workwage);
printf("\n\t\t 出生日期: ");
scanf("%s", pNew->wokerbir);
pNew->pNext = NULL;
//pNew = NULL;
for (p = pHead; p->pNext != NULL; p = p->pNext);
p->pNext = pNew;
printf("\n\t\t 添加成功...\n");
iCount++;
while (getchar() != '\n');
}
void Delete_Information()
{
char ID;
char sc;
int found = 0;
if (iCount == 0) {
printf("\n\t\t 员工信息为空!\n");
return;
}
PWOKE pCurrnode = pHead; //指向头结点
//head();
printf("\n\t\t 删除信息:\n");
printf("\n\t\t 请输入员工工号:");
scanf("%s", ID);
while (getchar() != '\n');
//遍历信息
while (pCurrnode->pNext != NULL)
{
if (strcmp(pCurrnode->pNext->workno, ID) == 0)
{
found = 1;
//信息库里面有要删除的信息
printf("\n\t\t 要删除的员工信息...\n");
printf("\n\t\t 工号\t姓名\t工资\t出生日期");
printf("\n\t\t %s\t %s\t %s\t %s\t\n", pCurrnode->pNext->workno,
pCurrnode->pNext->worname, pCurrnode->pNext->workwage, pCurrnode->pNext->wokerbir);
printf("\n\t\t 是否删除该信息(y/Enter):");
sc = getchar();
if(sc != '\n') while (getchar() != '\n');
if (sc == 'y' || sc == 'Y' || sc == '\n')
{
PWOKE pTemp = pCurrnode->pNext;
pCurrnode->pNext = pTemp->pNext;
free(pTemp);
iCount--;
printf("\n\t\t 删除成功...\n");
return;
}
else {
printf("\n\t\t 删除失败...\n");
return;
}
}
pCurrnode = pCurrnode->pNext;
}
if(!found)
printf("\n\t\t 没有找到要删除的信息......\n");
}
void Search_Information()
{
char ID;
PWOKE pCurrnode;
//head();
if (iCount == 0) {
printf("\n\t\t 员工信息为空!\n");
return;
}
printf("\n\t\t 查询信息:\n");
printf("\n\t\t 请输入员工工号:");
scanf("%s", ID);
pCurrnode = pHead->pNext;
while (pCurrnode != NULL)
{
if (strcmp(pCurrnode->workno, ID) == 0)
{
printf("\n\t\t 要查询的学生信息...\n");
printf("\n\t\t 工号\t姓名\t工资\t出生日期");
printf("\n\t\t %s\t %s\t %s\t %s\t\n", pCurrnode->workno,
pCurrnode->worname, pCurrnode->workwage, pCurrnode->wokerbir);
return;
}
pCurrnode = pCurrnode->pNext;
}
pCurrnode = NULL;
printf("\n\t\t 没有找到要查询的学生信息......\n\n");
while (getchar() != '\n');
}
void free_memory()
{
PWOKE p, q;
for (p = pHead; p != NULL; p = q) {
q = p->pNext;
free(p);
}
}
贴上代码后菜单就乱了,可以自己调整下。 superbe 发表于 2019-12-22 22:11
是在windows下还是linux下运行的呢。这是我在windows+visual studio中测试的代码,可以正常运行。如果在lin ...
感谢大佬
页:
[1]