数据与结构(c语言),代码运行不出来
下面是代码,求助一下。这个是一个窗口排队管理系统,我是新手,这些是小组一起做的,然后我们现在都不会找bug了。#include <stdio.h>
#include "util.h"
#include "winman.h"
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#definde MAXQSIZE 20
LNode* WIN_GetWinNodeById(SWinman &wm,WinId id);
void FreeLinkNode(void *p);
void FreeLinkNode(void *p)
{
SWin *win = (SWin *)p;
QueueFree(win->Q);
delete win;
}
//窗口开业
bool WIN_OpenALL(SWinMan &wm)
{
int id;
char type;
char szName;
SWin *win = NULL;
win.L=LL_Init();
if (!win.L)return false
//
win.C = WINCFG_Open();
if(!win.C) return fase;
while (WINCFG_MoveNext(win.C))
{
VERIFY(WINCFG_Read(win.C, id,type,szName));
win = new SWin;
memset(win,0, sizeof(SWin));
win->id = id;
win->pause = false;
win->Q = QueueInit(MAXQSIZE,sizeof(SQElem));
VERIFY(LL_AppendNode(win.L,win) !=NULL);
}
return true;
}
void WIN_CLoseALL(SWinMan &win)
{
LL_Free(win.L,FreeLinkNode);
WINCFG_Close(win.C);
win.C = NULL;
}
void WIN_Pause(SWinMan &win, WinId id, bool puse)
{
SWin *win = WIN_GetWinById(win,id);
if (win) win->pause = pause;
}
bool WIN_New(SWinMan &win, char type, WinId);
{
SWin *win = new SWin;
mement(win,0, sizeof(SWin));
if(!win) return false;
if (!WINCFG_New(win.C, type,win->id))
{
delete win;
return false;
}
win->pause = false;
win->Q = QueueInit(MAXQSIZE,sizeof(SQElem));
VERIFY(LL_AppenNode(win.l,win) !=NULL);
id = win->id;
return true;
}
bool WIN_Del(SWinMan &win,WinId id)
{
LNode *p = WIN_GetWinNodeById(win, id);
if (!p) return false;
SWin *win = (SWin*)p->data;
if(!QueueIsEmpty (win->Q)) return false;
LL_DeleteNode(win.L, p, FreeLinkNode);
WINCFG_Del(win.C, id);
return true;
}
SWin* WIN_GetWinById(SWinMan &win,WinId id)
{
LNode *p = WIN_GetWinNodeById(win,id);
if (p) return (SWin *)p->data;
return NULL;
}
LNode* WIN_GetWinNodeById(SWinMan & win,WinId id)
{
LNode *p = LL_GetFirstNode(win.L);
SWin *win
while (p)
{
win = (SWin*)p->data;
if(win->id == id) return p;
p= LL_GetNode(win.L,p);
}
return NULL;
}
void OnWinShow(void *para);
void OnWinNew(void *para);
void OnWinDel(void *para);
void OnWinPause(void *para);
void OnWinResume(void *para);
void OnCustomerArrive(void *para);
void OnCustomerLeave(void *para);
void OnWinManage(void *para)
{
SCmd acmd[] = {{"WinShow", "窗口状态", OnWinShow},
{"WinNew", "窗口新增", OnWinNew},
{"WinDel", "窗口删除", OnWinDel},
{"WinPause","窗口业务暂停", OnWinPause},
{"WinResume", "窗口业务恢复", OnWinResume},
{"", "", NULL},
{"CustomerArrive","取号排队", OnCustomerArrive},
{"CustomerLeave", "办结离队", OnCustomerLeave}
};
SWinMan win = ;
if (!WIN_OpenALL(win)) RETURN_MSG("模拟窗口排队系统")
CmdLoop(acmd, numof(acmd), &win);
WIN_CloseALL(win);
}
void OnWinShow(void *para)
{
SWinMan &win = *(SWinMan*)para;
LNode *p = LL_GetFirstNode(win.L);
SWin *win;
int num = 0;
char type;
char szName;
char szWin ;
PRINTF("窗口\t业务\t\状态\t排队人数\n");
while (p)
{
win = (SWin*)p->data;
VERIFY(WINCFG_ReadById(win.C,win->id,type,szName));
sprintf(szWin,"%c-%s",type,szName);
PRINTF("%d\t%s\t%d\n",win->id,szWin,win->Q);
num += win->Q-》num;
p=LL_GetNextNode(win.L,p);
}
PRENTF("共有%d人排队.\n", num);
}
void OnWinNew(void *para)
{
SWinMan &win = *(SWinMan*)para;
WinId id;
char szTip = {0};
char *p;
char chType;
strcpy(szTip,"请输入窗口类型(");
p = szTip + strlen(szTip);
WINCFG_DefDesc(p);
strcat (szTip,"):");
if (!InputChar(chType,szTip))return;
if (!WIN_NEW(win,chType, id))RETURN_MSG("操作失败!\n");
}
PRINTF("新增窗口%d成功!\n",id);
void OnWinDel(void *para)
{
SWinMan &win =*(SWinMan*)para
WinId id;
SWinMan &win = *(SWinMan *)para;
WinId id;
if(!InputInteger(id,"请输入待删除窗口的窗口号:")
if (!WIN_Del(win,id))RETURN_MSG("操作失败!\n") ;
PRINTF("窗口%d被成功删除!\n",id);
}
//窗口业务暂停
void OnWinPause(void *para)
{
SWinMan &win =*(SWinMan*)para;
WinId id;
if (!InputInteger(id,"请输入待暂停窗口的窗口号:"))
WIN_Pause(win,id,true);
PRINTF("窗口%d被成功暂停!\n",id);
OnWinShow(para);
}
//窗口业务恢复
void OnWinResume(void *para)
{
SWinMan &win =*(SWinMan*)para;
WinId id;
SWin *win;
if (!InputInteger(id,"请输入待暂停窗口的窗口号:"))
win = WIN_GetWinById(win,id);
if(!win) RETURN_MSG("指定窗口号不存在!\n") ;
if (!win->puase) RETURN_MSG("该窗口已经是正常状态,恢复成功!\n")
WIN_Pause(win,id,false);
PRINTF("窗口%d被成功恢复!\n",id);
OnWinShow(para);
}
void OnCustomerArrive(void *para)
{
SWinMan &win = *(SwinMan*)para
Swin *win,*winmin = NULL;
LNode *node = LL_GetFirstNode(win.L);
char szTip = {0};
char type,*p;
SQElem qelem = {0};
strcpy(szTip,"请输入需办理业务的类型(");
p = szTip + strlen (szTip);
WINCFG_DefDesc(p);
strcat(szTip,"):");
if (!InputChar(type,szTip)) return;
type = UppercaseChar(type);
while (node)
{
win = (SWin*)node->data;
if ((!win->pause) && WINCFG_GetType(win.c,win->id))
{
if (!winmin) winmin = win;
if (winmin->Q->num>win->Q->num,winmin=)
}
node=LL_GetNextNode(win.L,node);
}
if (!winmin)RETURN_MSG("当前无窗口可办理该业务!\n")
if (QueueIsFull(winmin->Q)) RETURN_MSG("所以队列均满\n")
winmin->nMaxQueueId++;
PRINTF("您到%d窗口办理业务,排队号为%c-%d,您面前有%d个人,win.L")
qelem.nId = winmin->nMaxQueueId;
qelem.nEnterTick = GetTickCount ();
if(QueueEnter(winmin->Q,&qelem,sizeof(qelem)) !=OK)
}
void OnCustomerLeave(void *para)
{
SWinMan &win = *(SWinMan*)para;
SWin *win , *winmin = NULL;
LNode *node = LL_GetFirstNode(win.L);
SQElem *a,*b,e;
while(node)
{
win= (SWin*)node->data;
if ((!win->pause) && (win->Q->num > 0))
{
if(!winmin) winmin = win
a = (SQElem*)QueueGetHead(winmin->Q);
b = (SQElem*)QueueGetHead(win->Q);
if (a->nEnterTick > b->nEnterTick) winmin =
}
node = LL_GetNextNode(win.L,node);
}
if (!winmin) RETURN_MSG("各窗口无排队,无人离队!\n")
a = (SQElem*)QueueGetHead(winmin->Q);
if (QueueLeave(winmin->Q,&e, sizeof(e)) !=OK) RETURN_MSG("")
PRINTF("%d号窗口%d号顾客离队!\n",winmin->id,e,nI)
}
这段代码存在许多语法错误和潜在的逻辑错误。下面我列出了一些明显的问题:
1.#definde MAXQSIZE 20应该是#define MAXQSIZE 20
2.void WIN_CLoseALL(SWinMan &win)中的函数名应为 void WIN_CloseALL(SWinMan &win) ,另外函数名和括号之间的全角字符应更改为半角字符。
3.bool WIN_OpenALL(SWinMan &wm)和其他函数中的SWinMan &wm这样的语法在 C 语言中是无效的,C 语言不支持引用,它只支持指针,所以应该改为SWinMan *wm 。当你要更改wm的内容时,需要使用wm->xxx而不是wm.xxx 。
4.bool WIN_New(SWinMan &win, char type, WinId);这行代码后面的分号是不需要的,而且函数的参数列表中WinId后面没有变量名。
5.mement(win,0, sizeof(SWin));这行代码中的mement应该是memset 。
6.return fase;应该是return false; 。
7.PRINTF应该是printf ,在 C 语言中没有PRINTF这个函数,所有的字母都是小写的。
8. 类似PRINTF("窗口\t业务\t\状态\t排队人数\n");这样的代码中的转义字符\在\状态前面是多余的,应该是"窗口\t业务\t状态\t排队人数\n" 。
9.SWinMan win = ;这是错误的,C 语言中没有这种语法。你可能想要初始化SWinMan结构体的所有成员为 0,那么可以使用SWinMan win = {0}; 。
10.if (!WIN_OpenALL(win)) RETURN_MSG("模拟窗口排队系统")这里RETURN_MSG是未定义的。这是你的自定义宏或函数吗?
11. 一些函数的定义和调用中混淆了SWinMan &win和SWin *win ,这样很容易导致编译错误或者运行时错误。你应该更仔细地检查你的代码以确保你正在对正确的变量进行操作。
12. 多处用到的VERIFY宏或者函数也是未定义的。你需要提供这个宏或者函数的定义。
13. 在多个地方,如while (WINCFG_MoveNext(win.C))中, WINCFG_MoveNext和其他WINCFG开头的函数没有在你的代码中定义。
14.if (winmin->Q->num>win->Q->num,winmin=)这里的赋值语句是不完整的。
这个代码存在大量的错误,需要进一步的修改才能运行。我强烈建议你在写代码的时候使用一些 IDE,如 Visual Studio Code、CLion 等,它们可以在你写代码的过程中发现这些基本的语法错误,甚至还有一些潜在的逻辑错误。我也建议你先学习一些 C 语言的基本知识,然后再尝试编写这种比较复杂的代码。 isdkz 发表于 2023-6-5 11:29
这段代码存在许多语法错误和潜在的逻辑错误。下面我列出了一些明显的问题:
1.#definde MAXQSIZE 20 ...
谢谢你,我们按照你指出的问题,尝试整改{:5_109:}
页:
[1]