小编cla*_*ntl的帖子

C 中的 While 循环在 Repl.it 中退出,但在使用 gcc 在本地运行时不退出

我对 C 相当陌生,但我的老师要求我实现一个链表。

当我在 Repl.it 中运行下面的代码时,它可以工作,但是当我在我的机器上使用 Windows 上的 gcc 运行它时,它不会退出 while 循环。

有任何想法吗?

#include <stdio.h>
#include <stdlib.h>

struct node *newNode(int);
void llAppend(int);
void llPrint(void);

struct node {
  int data;
  struct node *next;
};

struct node *ll;

int main(void) {

    llAppend(2);
    llAppend(3);

    llPrint();
}

struct node *newNode(int data) {
  struct node *tmp;

  tmp = malloc(sizeof (struct node));
  tmp->data = data;

  return tmp;
}

void llAppend(int data) {
  struct node *tmp;
  
  if (ll == NULL) {
    ll = newNode(data);
    return;
  }

  tmp …
Run Code Online (Sandbox Code Playgroud)

c struct linked-list while-loop

3
推荐指数
1
解决办法
98
查看次数

标签 统计

c ×1

linked-list ×1

struct ×1

while-loop ×1