ansh11
Member level 4
Hello
I want to make single linked list
When I compile code GCC compiler gives many warning
I want to make single linked list
When I compile code GCC compiler gives many warning
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include <stdio.h> #include <stdlib.h> struct Node{ int N; struct Node *next; }; struct Node *addNode(struct node *next , int n ) { struct Node *new = malloc(sizeof(*new)); new->N = n; new->next = next; return new; } int main ( ) { struct Node *head = NULL; head = addNode(1, head); return 0; }
How to make linked listwarning: 'struct node' declared inside parameter list will not be visible outside of this definition or declaration
struct Node *addNode(struct node *next , int n ) {
^~~~
: In function 'addNode':
warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
new->next = next;
^
In function 'main':
warning: passing argument 1 of 'addNode' makes pointer from integer without a cast [-Wint-conversion]
head = addNode(1, head);
^
note: expected 'struct node *' but argument is of type 'int'
struct Node *addNode(struct node *next , int n ) {
^~~~~~~
warning: passing argument 2 of 'addNode' makes integer from pointer without a cast [-Wint-conversion]
head = addNode(1, head);
^~~~
note: expected 'int' but argument is of type 'struct Node *'
struct Node *addNode(struct node *next , int n ) {
^~~~~~~