0

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
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by sam511
0

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");
0

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 .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.