i made a stack using linked list (without array). but my pop function is not working. even though it should : in my pop function, i store the address of head in temp,and go forward. then when i get a dead-end in temp. i remove it by putting NULL. but when i am printing the stack, it is not removing the last push.

i have tried using temp->next=NULL . only then it is working. but if temp->next=null is working. shouldnt "temp=NULL" also work?


    #include <stdio.h>
    #include <stdlib.h>
    #include<string.h>
    struct student{
    char name[20];
    int id;
    double cgpa;
    struct student* next;
    }*head;
    void print(){
    struct student*temp=head;
    while(temp!=NULL){
        printf("id %d name %s cgpa %lf\n",temp->id,temp->name,temp->cgpa);
        temp=temp->next;
    }
    }
    void push(struct student* temp){
    if(head==NULL){
        head=temp;
        return;
    }
    struct student* current=head;
    while(current->next!=NULL){
        current=current->next;
    }
    current->next=temp;
    }
    void pop(){
    struct student* temp=head;
    if(head==NULL){
        printf("\n no element to pop\n");
    }
    else{
    while(temp->next!=NULL){
        temp=temp->next;
    }
    temp=NULL;
    }
    }
    int main(){
        char operation;
        struct student* temp=NULL;
    head=NULL;
    
    while(1){
            // a for ADD, r for POP, s for print
        scanf("%c",&operation);
        if(operation=='a'){
            temp=(struct student*)malloc(sizeof(struct student));
            scanf("%d %s %lf",&temp->id,&temp->name,&temp->cgpa);
            temp->next=NULL;
            push(temp);
        }
        else if(operation=='r'){
            pop();
        }else if(operation=='s'){
        print();
        }
    }
    }



a
1 joy 2.3
a
5 boy 3.3
s
r
s


the expected result should be

1 joy 2.3
5 boy 3.3

1 joy 2.3

but actual results are 
1 joy 2.3
5 boy 3.3

1 joy 2.3
5 boy 3.3