Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Creating Linked List

Status
Not open for further replies.

ansh11

Member level 4
Member level 4
Joined
Feb 27, 2018
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
659
Hello

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;
}



warning: '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 ) {
^~~~~~~
How to make linked list
 

I think you need to understand c before attempting writing a linked list. You also need to understand the compiler warnings and errors. By looking at struct node, where is that declared? Also you returning a struct Node, what is the difference between the capitalize and lower case structs? Have you tried typedef?

I don't know your code but if you going to attempt to write a linked list there are plenty of examples online or in standard c book.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top