本文介绍了C程序中的错误 - 预期“char *”但参数是char类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 所以我一直在编写这个程序,我是一个新手所以请原谅我的意大利面条代码,当我试图执行这个代码时我遇到了一个错误,我只是想弄清楚原因。 #include< stdio.h> #include< stdlib.h> #include< string.h> struct listNode { char data; struct listNode * nextPtr; }; typedef struct listNode ListNode; typedef ListNode * ListNodePtr; / * prototypes * / char insert(ListNodePtr * head,char value); void printList(ListNodePtr currentPtr); int isEmpty(ListNodePtr sPtr); void main() { ListNodePtr startPtr = NULL; char item; printf(输入字符\ n); insert(& startPtr,item); printList(startPtr); } char insert(ListNodePtr * head,char value) { ListNodePtr newptr; ListNodePtr currentptr; ListNodePtr previousptr; newptr = malloc(sizeof(ListNode)); if(newptr!= NULL) { strcpy(newptr-> data,& value); newptr-> nextPtr = NULL; previousptr = NULL; currentptr = * head; if(previousptr == NULL) { newptr-> nextPtr = * head; * head = newptr; } / * end if * / else / *在previousPtr和currentPtr之间插入新节点* / { previousptr-> nextPtr = newptr; newptr-> nextPtr = currentptr; } / * end else * / / * end if * / } else { printf(%s未插入。无记忆available.\\\,value); } } void printList(ListNodePtr currentPtr) { if(isEmpty(currentPtr)) { puts(List is empty.\); } 其他 { puts(列表是:); while(currentPtr!= NULL) { printf(%s - >,currentPtr-> data); currentPtr = currentPtr - > nextPtr; } puts(NULL\\\); } } int isEmpty(ListNodePtr sPtr) { return sPtr == NULL; } 我得到的错误就是这个; [ ^ ] 请帮帮我。伙计们' 我尝试了什么: 错误似乎来自这部分代码; strcpy(newptr-> data,& value); newptr-> nextPtr = NULL; previousptr = NULL; currentptr = * head; 就像我说的,我是一个绝对的新手,除了google之外,我还没有尝试过多少但是仍然无法找到解。在此先感谢您的帮助!解决方案 So Ive been writing this program, and Im a novice so please excuse my spaghetti code, I run into an error when Im trying to execute this code and I just cant figure out why.#include <stdio.h>#include <stdlib.h>#include <string.h>struct listNode{char data;struct listNode *nextPtr;};typedef struct listNode ListNode;typedef ListNode *ListNodePtr;/*prototypes*/char insert( ListNodePtr *head, char value);void printList( ListNodePtr currentPtr );int isEmpty( ListNodePtr sPtr);void main(){ListNodePtr startPtr = NULL;char item; printf("Enter the character\n");insert(&startPtr,item);printList(startPtr);}char insert( ListNodePtr *head, char value){ListNodePtr newptr;ListNodePtr currentptr;ListNodePtr previousptr;newptr = malloc( sizeof( ListNode ));if(newptr !=NULL){strcpy(newptr->data,&value);newptr->nextPtr= NULL;previousptr=NULL;currentptr = *head; if ( previousptr == NULL ){newptr->nextPtr = *head;*head = newptr;} /* end if*/else /* insert new node between previousPtr and currentPtr*/{previousptr->nextPtr = newptr;newptr->nextPtr = currentptr;} /* end else*/ /* end if*/}else{printf( "%s not inserted. No memory available.\n", value );}}void printList( ListNodePtr currentPtr ){if ( isEmpty( currentPtr )){puts( "List is empty.\n" );}else{puts( "The list is: " );while ( currentPtr != NULL ){printf( "%s --> ", currentPtr->data );currentPtr = currentPtr ->nextPtr;}puts( "NULL\n" );}}int isEmpty( ListNodePtr sPtr ){return sPtr == NULL;}The error im getting is this;[^]Please help me.out guys'What I have tried:The error seems to be from this part of code;strcpy(newptr->data,&value);newptr->nextPtr= NULL;previousptr=NULL;currentptr = *head;And like I said, Im an absolute novice and I havent tried much other than google this but still cant find the solution. Thanks in advance for your help! 解决方案 这篇关于C程序中的错误 - 预期“char *”但参数是char类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 06:49