structurとpointers.passingの関数で構造体にアクセスし、構造体のメンバーにアクセスしていましたが、エラーが発生しました。機能には 'メイン':これは構造体とポインタのコンセプト
main.cの私のコードはエラーであるコンパイル後
#include<stdio.h> #include<stdlib.h> enter code here struct node { int32_t data; struct node *next; }; void SLL_insert_beg( struct node *head_lst ){ int32_t num_lst; struct node *temp_lst,*new_lst; //intialising local variable. new_lst = (struct node*)malloc(sizeof(struct node)); //Allocating dynamic memory for node new. printf(" Enter data: "); scanf("%d", &num_lst); new_lst->data = num_lst; //inserting data into the datafield in node new. if(head_lst == NULL) { //Condition to check list is empty in SLL_insert_beg() function. new_lst->next = NULL; //Making pointer field to point null in node new. head_lst = new_lst; //Making new node as head node. } else { new_lst->next = head_lst; //pointer field in new node points to the head node. head_lst = new_lst; //Making new node as head node. } } void SLL_display( struct node *head_lst ) { struct node *temp_lst,*new_lst; int32_t i_lst = 1 ; //intialising local variable. if(head_lst == NULL) { //Condition to check list is empty in SLL_display() function. printf(" List is empty!! "); } else { temp_lst = head_lst; //Making head node as temp node. printf("\nThe linked list is:\n "); printf(" Elements: "); /*Below loop used to print all elements in single linked list*/ while(temp_lst != NULL) { printf("%d-> ", temp_lst->data); temp_lst = temp_lst->next; //Making temp next node as temp node. } printf("NULL\n "); printf(" Position: "); temp_lst = head_lst; //Making head node as temp node. /*Below loop used to print no.of positions in single linked list*/ while(temp_lst != NULL) { printf("%d " , i_lst); i_lst = i_lst + 1; //Incrementing variable 'i_lst' once. temp_lst = temp_lst->next; //Making temp next node as temp node. } } } void main(void) { //sll_program(void) { int32_t data; int32_t SL_ch; //Intialised a variable used to choose the option in the below menu. struct node *head_lst=NULL; struct node *temp_lst,*new_lst; while(1) { printf(" \n\nSingly Linked List(SLL)"); printf(" \n1.Insert beg \ \n2.diplay \ \n3.exit " ); printf("\nEnter your choice(1-4):"); scanf("%d",&SL_ch); switch(SL_ch) { case 1: //If choice is 1 calls insert at beginning function. SLL_insert_beg( &head_lst ); break; case 2: SLL_display( &head_lst ); //If choice is 2 calls the display function. break; case 3: return; default: printf("Please give the right choice!!"); } } }
のmain.c:91:63:警告:の引数1を渡します12::6:注:[デフォルトで有効になって] 互換性のないポインタ型
のmain.cから 'SLL_insert_beg' '構造体のノード*' が、引数期待がタイプ '構造体ノード**' である
SLL_insert_beg(構造体ノード* head_lst main.c:98:62:警告: 'SLL_display'の引数1を渡します。 互換性のないポインタ型[デフォルトで有効]
); // choiceが2の場合、display関数が呼び出されます。のmain.c:6:34注意:期待される '構造体のノード*' が、引数の型 である '構造体ノード**'
無効SLL_display(構造体のノード* head_lst
コードを最小限に抑えてください。だから我々は助言を提供することができます。 – Massey101
コンパイラが発行するエラーメッセージにはどのような不明点がありますか? – alk