hi guys i need some help can you guys help me at deleting nodes I'm not yet that good in linked list and I can only delete the first node but I can't delete nodes in the middle and at the last help please I'm making a student database where we can create courses and student accounts thanks

void deleteclass(ptrClass *pFirst,int arr[])
{
     int a;
     int i=0;
     ptrClass current,trail;
     
     current = *pFirst;
     
     //dview();
    
    
    
     if(arr[0] != 0)
     {
     do
     {
     //dview();          
     printf("\t\t\t[1] for next\n\t\t[2] for Previous \n\t\t[3] for delete\n\t\t[4] Exit\n\n");          
     printf("\t\t[course code] : %s \n\n",current->coursecode);
        printf("\t\t[section] : %d \n\n",current->section);
            printf("\t\t[number of the units] : %d \n\n",current->units);
               printf("\t\t[The schedule] : %s \n\n",current->schedule);
               printf("\t\t[Starting time %d:%d End Time %d:%d \n\n",current->pTime.shours,current->pTime.smin,current->pTime.ehours,current->pTime.emin);
                  printf("\t\t[Name of the lecturer] : %s \n\n",current->lecturer);
                     printf("\t\t[total slots] : %d\n\n",current->slots);
     
     scanf("%d",&a);  
     //for menu functions
     if(a==1)
     {
     system("cls");    
     if(current->pNext != NULL)   
     current= current->pNext;
     
     if(current->pNext == NULL)
     {
       system("cls");
}
    
     i++;
     if(i > arr[0])
     current = current->pPrev;
     }
     else if(a==2)
     {
     system("cls");   
     current = current->pPrev; 
     i--;          
       if( i < 0)
       i = arr[0] - 1;  
     }
     
     if(a == 3)
     {
        
      
      if(*pFirst == current)
      *pFirst = (*pFirst)->pNext;  
      
    //  else if(current->pNext != NULL)
      
      else if(current->pNext == NULL)
    {
      current->pPrev = current->pNext;
      
      }
    
      free(current);
        
      }
     
     else if(a==4)
     {
     system("cls");    
     i=7; 
     }               
     }while(i<6);
     system("cls");
}
      else
     printf("\n\n\n\n\n\n\t\t\t\t[There's no class created] \n");
     
     sleep(1000);
     system("cls");
     }

your program is quite confusing (atleast for me), but at line 64..
instead of

current->pPrev = current->pNext;

i think it should be

current->pPrev->pNext = current->pNext;
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.