gpt4 book ai didi

c - strcpy 和 strcmp 参数的类型不兼容

转载 作者:太空宇宙 更新时间:2023-11-04 03:11:50 27 4
gpt4 key购买 nike

(所有字符串)我需要通过将给定的用户名(Item)与记录的用户名队列进行比较来检查它是否已经登录。但是当我尝试使用 strcmp 对它们进行 campare 时,我在标题中得到了错误。稍后我也有一个 strcpy 将用户名添加到队列中,但出现相同的错误。我该如何处理这些问题?

这些是我的结构

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;
}

最佳答案

strcpy(TempPtr->Data,Item.userid);
strcmp(CurrPtr->Data,Item.userid)

此处 Data 的类型为 QueueElementType

但是 strcpystrcmp\0 终止的 char * 作为参数。

将其更改为。

strcpy(TempPtr->Data.userid,Item.userid);
strcmp(CurrPtr->Data.userid,Item.userid)

关于c - strcpy 和 strcmp 参数的类型不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55591475/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com