strcpy 和 strcmp 参数的类型不兼容

Incompatible type for argument of strcpy and strcmp

(所有字符串)我需要检查给定的用户名(项目)是否已经登录,方法是将其与已记录的 usernames.But 队列进行比较,当我尝试使用 strcmp 对它们进行 campare 时,我得到了错误title.Later 我也有一个 strcpy 可以在队列中添加相同的用户名 error.How 我可以处理这些问题吗?

这些是我的结构

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)

这里的DataQueueElementType的类型。

但是 strcpystrcmp[=16=] 终止 char * 作为参数。

改成。

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

尝试

strcmp(CurrPtr->Data.userid,Item.userid)

as strcmp() 需要 const char* 的参数,但是 CurrPtr->DataQueueElementType 类型而不是 const char* 类型。来自 strcmp.

的手册页

int strcmp(const char *s1, const char *s2);

同样适用于 strcpy()。这个

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

制作成

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