C 调用函数期间出现不兼容的指针类型错误
我想创建一个程序,它将实现一个行编辑器,将行作为输入并打印它们 我使用游标来操作单链接列表,但由于指针类型不兼容,displayFromCursor、displayAll、moveCursor函数中出现错误,我哪里出错了? 请帮帮我,我现在被困在这里了C 调用函数期间出现不兼容的指针类型错误,c,pointers,linked-list,C,Pointers,Linked List,我想创建一个程序,它将实现一个行编辑器,将行作为输入并打印它们 我使用游标来操作单链接列表,但由于指针类型不兼容,displayFromCursor、displayAll、moveCursor函数中出现错误,我哪里出错了? 请帮帮我,我现在被困在这里了 #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<string.h> typedef struct node {
#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("BYE\n");
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("%s\n",(*pCursor)->next->line);
displayFromCursor( ((*pCursor)->next) );
}
return;
}
void displayAll(LIST **pList)
{
if((*pList)->link !=NULL)
{
printf("%s\n",(*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 cursor\n");
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;
}
#包括
#包括
#包括
#包括
类型定义结构节点
{
字符行[300];
结构节点*链接;
}节点;
typedef结构游标
{
节点*prev;
节点*下一步;
}光标;
类型定义结构列表
{
节点*链接;
整数计数;
}名单;
void take命令(光标**pCursor,列表**pList);
作废插入行(光标**pCursor,列表**);
作废删除行(光标**pCursor,列表**pList);
作废移动光标(光标**pCursor,列表**pList);
void displayFromCursor(光标**pCursor);
作废显示全部(列表**pList);
真空总管(真空)
{
列表*pList;
pList->count=0;
pList->link=NULL;
光标*pCursor;
pCursor->prev=NULL;
pCursor->next=NULL;
takeCommand(&pCursor,&pList);
printf(“再见”);
返回;
}
void take命令(光标**pCursor,列表**pList)
{
字符c;
printf(“>”);
c=getchar();
开关(c)
{
案例“I”:插入线(pCursor,pList);
案例“D”:删除行(pCursor,pList);
案例“M”:移动光标(pCursor,pList);
案例“L”:displayFromCursor(pCursor);
案例“A”:displayAll(pList);
案例“X”:返回;
默认值:printf(“再次输入正确值”);
}
takeCommand(pCursor,pList);
}
void insertLine(光标**pCursor,列表**pList)
{
字符换行符[300];
布尔x=真;
做
{
if(strcmp(换行“/”)
{
x=假;
}
其他的
{
scanf(“%s”,换行符);
节点*pNew;
pNew=(NODE*)malloc(sizeof(NODE));
strcpy(pNew->line,newLine);
pNew->link=(*pCursor)->下一步;
(*pCursor)->prev=pNew;
((*pList)->计数)+;
}
}虽然(正确);
返回;
}
作废删除行(光标**pCursor,列表**pList)
{
节点*温度;
临时->链接=(*pCursor)->下一步;
(*pCursor)->next=(*pCursor)->next)->link;
免费(临时);
((*pList)->count)--;
返回;
}
void displayFromCursor(光标**pCursor)
{
if((*pCursor)->next!=NULL)
{
printf(“%s\n”,(*pCursor)->next->line);
displayFromCursor(((*pCursor)->next));
}
返回;
}
无效显示全部(列表**pList)
{
如果((*pList)->link!=NULL)
{
printf(“%s\n”,(*pList)->link->line);
displayFromCursor((*pList)->link));
}
返回;
}
无效移动光标(光标**pCursor,列表**pList)
{
int countNew=(*pList)->count;
内部温度,i;
printf(“输入移动光标的编号\n”);
scanf(“%d”、&temp);
countNew-=温度;
while((*pCursor)->next!=NULL)
{
(*pCursor)=(*pCursor)->下一步;
新计数--;
}
(*pCursor)->next=(*pList)->link;
(*pCursor)->prev=NULL;
对于(i=0;iprev=(*pCursor)->next;
(*pCursor)->next=(*pCursor)->next->link;
}
返回;
}
问题已经解决
displayFromCursor(((*pCursor)->next));
函数displayFromCursor需要
struct CURSOR**
作为参数,但实际上参数的类型是struct NODE*
。类似地,在函数displayAll
中,您只需将pCursor
作为参数传递即可。注意,在Switch case语句中有一个失败的情况。您可以编程已编译,但出现运行时错误,需要进行调试。