c-调用函数时出现不兼容的指针类型错误



我想创建一个程序,实现一个行编辑器,该编辑器将行作为输入并打印

我正在使用游标来操作单链表,但由于指针类型不兼容,我在displayFromCursor、displayAll、moveCursor函数中遇到了错误,我在哪里出错了?请帮忙,我被困在这里了

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
typedef struct node
{
    char line[300];
    struct node *link;
}NODE;
typedef struct cursor
{
    NODE *prev;
    NODE *next;
}CURSOR;
typedef struct list
{
    NODE *link;
    int count;
}LIST;
void takeCommand(CURSOR **pCursor,LIST **pList);
void insertLine(CURSOR **pCursor,LIST**);
void deleteLine(CURSOR **pCursor,LIST **pList);
void moveCursor(CURSOR **pCursor,LIST **pList);
void displayFromCursor(CURSOR **pCursor);
void displayAll(LIST **pList);
void main(void)
{
    LIST *pList;
    pList->count = 0;
    pList->link = NULL;
    CURSOR *pCursor;
    pCursor->prev = NULL;
    pCursor->next = NULL;
    takeCommand(&pCursor,&pList);
    printf("BYEn");
    return;
}
void takeCommand(CURSOR **pCursor,LIST **pList)
{
    char c;
    printf(">");
    c=getchar();
    switch(c)
    {
    case 'I': insertLine(pCursor,pList);
        case 'D': deleteLine(pCursor,pList);
            case 'M': moveCursor(pCursor,pList);
                case 'L': displayFromCursor(pCursor);
                    case 'A': displayAll(pList);
                        case 'X':return;
                        default : printf("Enter correct value again");
    }
    takeCommand(pCursor,pList);
}
void insertLine(CURSOR **pCursor,LIST **pList)
{
    char newLine[300];
    bool x=true;
    do
    {
        if(strcmp(newLine,"//"))
        {
            x=false;
        }
        else
        {
            scanf("%s",newLine);
            NODE *pNew;
            pNew = (NODE*)malloc(sizeof(NODE));
            strcpy(pNew->line,newLine);
            pNew->link = (*pCursor)->next;
            (*pCursor)->prev = pNew;
            ((*pList)->count)++;
        }
    }while(true);
    return;
}
void deleteLine(CURSOR **pCursor,LIST **pList)
{
    NODE *temp;
    temp->link = (*pCursor)->next;
    (*pCursor)->next = ((*pCursor)->next)->link;
    free(temp);
    ((*pList)->count)--;
    return;
}
void displayFromCursor(CURSOR **pCursor)
{
    if((*pCursor)->next !=NULL)
    {
        printf("%sn",(*pCursor)->next->line);
        displayFromCursor( ((*pCursor)->next) );
    }
    return;
}
void displayAll(LIST **pList)
{
    if((*pList)->link !=NULL)
    {
        printf("%sn",(*pList)->link->line);
        displayFromCursor( ((*pList)->link) );
    }
    return;
}
void moveCursor(CURSOR **pCursor,LIST **pList)
{
    int countNew=(*pList)->count;
    int temp,i;
    printf("Enter the number to move cursorn");
    scanf("%d",&temp);
    countNew-=temp;
    while((*pCursor)->next !=NULL)
    {
        (*pCursor) = (*pCursor)->next;
        countNew--;
    }
    (*pCursor)->next = (*pList)->link;
    (*pCursor)->prev = NULL;
    for(i=0;i<countNew;i++)
    {
        (*pCursor)->prev = (*pCursor)->next;
        (*pCursor)->next = (*pCursor)->next->link;
    }
    return;
}

问题在行

displayFromCursor( ((*pCursor)->next) );

其中函数displayFromCursor期望struct CURSOR **作为参数,但实际上参数的类型是struct NODE *。类似于函数displayAll。您只需要将pCursor作为参数传递。

相关内容

  • 没有找到相关文章

最新更新