I am trying to make a linked list in C. I've got the program up and running in Turbo C++ which we use at school. When I try putting my code in Code Blocks I cannot get it running. I stripped a big part of the code so you can see the part that stops working when I debug. When it compiles it says nothing about an error but simply stops working. I am thinking it might me because of how I dynamically allocate memory.
#include <stdio.h>
#include <stdlib.h>
struct data
{
int a;
int b;
};
struct node
{
struct data info;
struct node *urm;
};
struct lista
{
int lungime;
struct node *curent, *prim, *ultim;
};
struct lista *listax;
int creare(struct lista *LP)
{
LP->prim = (struct node*)malloc(sizeof(struct node));
LP->ultim = (struct node*)malloc(sizeof(struct node));
LP->prim->urm = LP->ultim;
LP->ultim->urm = NULL;
LP->curent=LP->prim;
LP->lungime = 0;
return 1;
}
int main()
{
creare(listax);
return 0;
}
I have to use this type of declaration because this how our teacher wants us to present the list (with a start and end node). Any help is appreciated.
*edit:
prim is first
ultim is last
lungime is length
urm is next