ok we'll if I understand it correctly you want to keep 1 pointer which will point to the front of the list and one to the very last one. Probably easiest way would be slight modification from my last post:
Code:
int addvalue(MYRECORDS **lastptr, MYRECORDS *temprecord)
{
MYRECORDS *tempptr=*lastptr;
if(*recordptr==NULL) //IF NO RECORDS EXIST
{
*recordptr = (MYRECORDS *) malloc(sizeof(MYRECORDS));
tempptr=*recordptr;
}
else
{
while(tempptr->next!=NULL)
tempptr = tempptr->next;
tempptr->next = (MYRECORDS *) malloc(sizeof(MYRECORDS));
if(tempptr->next == NULL)
{
printf("MEMORY FULL\n");
return 1;
}
}
tempptr->next=NULL;
tempptr->number1=temprecord->number1;
tempptr->value=temprecord->value;
*lastptr=tempptr; // SAVES THE POINTER OF THE LAST RECORD
return 0;
}
ok and in the main function you would do something like
Code:
int main()
{
MYRECORDS *mainptr=NULL;
MYRECORDS *lastptr=NULL;
MYRECORDS temprecord;
// Create a record here called temprecord
addvalue(&lastptr,&temprecord);
if(mainptr==NULL) // Make mainptr point to the first record
mainptr=lastptr;
and loop around the last 3 statements everytime you add a record, because your passing the memory address of lastptr it can be updated inside the addvalue function, alternativally you could make it a global variable, eliminating the need for passing extra pointers to the function.