hello everybody,I'm a new member ,and i was hoping that you could help me with my problem . I'm making a secondary school system using linkedlist and files and i add students into two levels each one with a different linkedlist.
we are suppose to add ,update,delete,search,display and then save each list in a different file.
I want to make search function according to student's level and id
but it's just not working I Know I'm supposed to make the pointer move but i don't know how please HELP!!!!!
Here is my attempt

void search(struct school *move)
{
    
    int level,id ;
   
	/* check if list is empty  */
    
    move=head;

	if (move == NULL)
    { printf("\n\n\tThe list is empty "); 
	   
	}
    else 
    {  
		printf("\n\nEnter the level to search for : ");
        scanf(" %d",&level);
        printf("\n\nEnter the id to search for :");
		scanf("%d",&id);
		
	    if(move->level==level&&move->id==id)
	 	
		 {   
			 printf("\n\n Student Record Is  FOUND ") ; 
	          
		   wait();
		 }
			
				
        else
		{ 
	 		
		printf ("\n\n Student Record Is NOT FOUND  "); 
		
		wait();
		}
		
	 }//end else
	     
}//end function

Recommended Answers

All 2 Replies

There is not a loop anywhere in that function. It should loop over the nodes until NULL and stop early if a match is found:

int found = 0;

while (move != NULL)
{
    if (move->level == level && move->id == id)
    {
        found = 1;
        break;
    }

    move = move->next;
}

if (found) printf("\n\nStudent Record Is FOUND");
else printf ("\n\nStudent Record Is NOT FOUND");

SORRY !I completely forgot about the loop ,I used It in another attempt but it failed and I forgot to add It .
Thanks alot It's working .

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.