【发布时间】:2019-04-09 11:11:11
【问题描述】:
(所有字符串)我需要通过将给定的用户名(项目)与记录的用户名队列进行比较来检查它是否已经登录。但是当我尝试使用 strcmp 对它们进行露营时,我得到标题中的错误。稍后我也有一个strcpy在Queue中添加用户名,同样报错。这些问题该如何处理?
这些是我的结构
typedef struct{
char userid[8];
}QueueElementType;
typedef struct QueueNode *QueuePointer;
typedef struct QueueNode
{
QueueElementType Data;
QueuePointer Next;
} QueueNode;
typedef struct
{
QueuePointer Front;
QueuePointer Rear;
} QueueType;
检查队列中给定用户名的代码
boolean AlreadyLoggedIn(QueueType Queue, QueueElementType Item){
QueuePointer CurrPtr;
CurrPtr = Queue.Front;
while(CurrPtr!=NULL){
if(strcmp(CurrPtr->Data,Item.userid) == 0){
printf("You have logged in to the system from another terminal.New access is forbidden.");
return TRUE;
}
else CurrPtr = CurrPtr->Next;
}
return FALSE;
}
将给定的用户名添加到队列中
void AddQ(QueueType *Queue, QueueElementType Item){
QueuePointer TempPtr;
TempPtr= (QueuePointer)malloc(sizeof(struct QueueNode));
strcpy(TempPtr->Data,Item.userid);
TempPtr->Next = NULL;
if (Queue->Front==NULL)
Queue->Front=TempPtr;
else
Queue->Rear->Next = TempPtr;
Queue->Rear=TempPtr;
}
【问题讨论】:
-
if(strcmp(CurrPtr->Data,.. 数据不是 strcmp() 所需的 const char*
标签: c string pointers data-structures incompatibletypeerror