I want to delete the first element from a list.

this is my list:

struct dlist {
   int liber; //it translates as "free" don't know what this is
   int nmax; //maximum number of elements 
   DATA *pv; //a pointer with which i can move in list, also DATA is int
};
typedef struct dlist Lista, *LISTA;

//my try so far
//it deletes the first element but you can guess what happens when i reach the last element. I've tried w/o for to no avail.    

void delFirst(LISTA l)
{
    LISTA *temp; int i;
    if(!(empty(l)))
    temp=l->pv[0];
    for(i=0;i<(l->nmax)-1;i++)
        l->pv[i]=l->pv[i+1];

    free(temp);

}

If DATA is defined as int, struct * can not be assigned the value of int without a typecast.

line 19: You can not free() individual elements of an array. The number of elements of an array are fixed when the array is declared and can not be changed. The best you can do is mark the element as unused so that is can be reused when another element needs to be added. That's most likely the purpose of liber.

That temp pointer is not needed. There is no reason to save the value of p[0] since p[0] is nothing more than an integer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.