I need to make a linked list that stores integer data. Also the list needs to know its size (the number of items in the list).
This is my code.
linked.h file
typedef struct node Node;
struct node{
int a;
Node* b;
};
Node m;
typedef struct {
node* head;
int size;
}list;
list list1;
Main file
#include <stdio.h>
#include "linked.h"
list init(list list1)
{
list1.head = null;
list1.size = 0;
return list1;
}
void main()
{
list1=init(list1);
printf("%d",list1.size);
}
Now on running, the result is -” could not create process”,
using Turbo C on Windows.
- Why am I getting this result?
- Why is the process not being created?
- Also, is this how I should initialize a linked list?
There are two errors: First, you should write
Node* head;rather thannode* head;, and second, you should writeNULLor0instead ofnull.Probably your compiler messages are somehow suppressed.
And, yes, this is how you can initiate a linked list, but
would be better.
And there could be made other improvements as well.