This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

static structure in C keep list of information in memory

Hello everyone,

I would like to know how I can create a static data type structure where the information is always kept in memory even if it calls different functions or executes some other code outside its main function.

Every time I call a function the data is lost on the list.

typedef struct director_users dir_users;
struct director_users
{
	int count;				        //Id
	char name[10];			        //Name
	char time1[10];			        //Pos
	struct director_users *p1;
};
static dir_users *directorio=NULL;

When I create the linked list the information is stored correctly but when calling another function the information disappears from the list.

crearUserdir(directorio,"String1","String2");
functionTest();

Regards,

Parents
  • This is the code of funtion:


    dir_users * crearUserdir(dir_users *drusr, char name1[10],char time2[10])
    {
    	dir_users *aux1=NULL;
    	
    	dir_users *newnode= (dir_users*) malloc(sizeof(dir_users));
    	if(newnode)
    	{
    		strcpy(newnode->name,name1);
    		strcpy(newnode->time1,time2);
    
    		newnode->p1=NULL;
    		if(drusr==NULL)
    			drusr=newnode;
    		else
    		{
    			aux1=drusr;
    			while(aux1->p1!=NULL)
    			{
    				aux1=aux1->p1;
    			}				
    			aux1->p1=newnode;
    		}
    	}
    	return drusr;
    }

Reply
  • This is the code of funtion:


    dir_users * crearUserdir(dir_users *drusr, char name1[10],char time2[10])
    {
    	dir_users *aux1=NULL;
    	
    	dir_users *newnode= (dir_users*) malloc(sizeof(dir_users));
    	if(newnode)
    	{
    		strcpy(newnode->name,name1);
    		strcpy(newnode->time1,time2);
    
    		newnode->p1=NULL;
    		if(drusr==NULL)
    			drusr=newnode;
    		else
    		{
    			aux1=drusr;
    			while(aux1->p1!=NULL)
    			{
    				aux1=aux1->p1;
    			}				
    			aux1->p1=newnode;
    		}
    	}
    	return drusr;
    }

Children