Unity探路者 2016-10-27 15:57 采纳率: 0%
浏览 984

一样的代码在notepad能运行,但在VC上怎么不行啊?求大神解答

#include
#include

struct Node * create_list(void);
void traverse_list(struct Node *);

struct Node
{
int data;
struct Node * pNext;
};

int main(void)
{
struct Node * pHead = NULL;

pHead = create_list();
traverse_list(pHead);

return 0;

}

struct Node * create_list(void)
{
int val;
int i;
int len;

struct Node * pHead = (struct Node *)malloc(sizeof(struct Node));

if (pHead == NULL)
{
    printf("分配失败,程序中止!\n");
    exit(-1);
}
struct Node *pTail = pHead;
pTail->pNext = NULL;

printf("请输入您要生成的链表的节点的个数:len = ");
scanf ("%d", &len);

for (i = 0; i < len; i++)
{
    printf("请输入第%d个节点数据域的值: ", i+1);
    scanf("%d", &val);

    struct Node * pNew = (struct Node *)malloc(sizeof(struct Node));
    if (NULL == pNew)
    {
        printf("分配失败,退出程序!\n");
        exit(-1);
    }
    pNew->data = val;
    pTail->pNext = pNew;
    pNew->pNext = NULL;
    pTail = pNew;
}

return pHead;

}

void traverse_list(struct Node *pHead)
{
struct Node * p = pHead->pNext;

while ( p != NULL)
{
    printf("%d\n", p->data);
    p = p->pNext;
}

}

  • 写回答

4条回答 默认 最新

  • threenewbee 2016-10-27 16:08
    关注

    vc++你新建的什么类型的程序?是控制台么?不要删除默认的代码中的include stdafx.h
    把你的代码贴在下面。

    如果还不行,贴出错误

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作