Hello all,

I am writing a function for a program which takes the first number from a linked list and uses it elsewhere in the program. It is meant to take the start pointer and if that number is the last number in the list, generate 10 more numbers.

But, it seems to take the LAST pointer from the list and it does not remove it from the list properly because the next time a number is needed it is the same one. The code is as follows:

Code:
int removeFromList(NODE *startPtr)
{  
   int number, a;
   NODE *currentPtr,*previousPtr;

   previousPtr = currentPtr = startPtr;
   currentPtr = startPtr->nextPtr;

   if(currentPtr->nextPtr == NULL)
   {

     /* generate more numbers */

      number = currentPtr->number; 
      for(a = 1; a <= 10; a++)
      {
          number = (number + 11) DIV 10;
          number = createNewNumber(number);
          addToList(currentPtr, number);
      }
   }

   else
   {

     /* I think the problem is here */

      while(currentPtr->nextPtr != NULL)
      {
        previousPtr = currentPtr;
        currentPtr = currentPtr->nextPtr;
      }
      number = currentPtr->number;
      previousPtr->nextPtr = NULL;
   }
  return number;
}


The 10 new numbers are generated successfully when required. The problem is just reading the first number and then removing it from the list.

*** Thanks for your help. ***