如何退出队列中的 while 循环?

How can I exit the while loop in queue?

如何退出 while 循环?

我尝试了 NULL、'\0' 和 '\n' 但没有任何效果。如果用户键入空行或空字符,我将尝试退出循环。我使用了 == NULL 但它没有进入循环。

我该如何退出 fgets 循环?

代码

typedef struct node{
    char *num;
    struct node *next;
}Node, *NodePtr;


NodePtr makeNode(char *n){

    
    NodePtr np = (NodePtr) malloc(sizeof(Node));
    np -> num = n;   // (*np).num
    np -> next = NULL;
    return np;
}
// prints all the items in the list
void printList(NodePtr np){
    while(np != NULL){ // as long as there's a node
        printf("%s\n",np ->num );
        np = np -> next; //go  on to the next node
    }
}// end print list


// main function

int main(void){

    char n[10];
    NodePtr top,np,last;
    top = NULL;

    if(fgets(n,sizeof n,stdin) != NULL){
    
        while(n != '[=10=]'){
            np = makeNode(n);    // create a new node containing n
            if(top == NULL){     // set top if first node
                top = np;
            }
            else{
                last->next = np; // set last-> next for other nodes
            }
            last = np;           //keepin track of last node
            if(fgets(n,sizeof n,stdin) != NULL){
                //do  nothing
                
                printf("User enter null\n" );
            }
            

        }
    }
    printList(top);
    return 0;
} // end main

看起来n是一个指向char数组的指针。考虑尝试检查

while(!(n[0] == '[=10=]') && !(n[0] == '\n'))

检查新行和空字符