【C语言求助】静态链表执行赋值语句时暂停运行

飞禽走兽卍一2b 2021-04-19 08:26:32
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
}node;
void main()
{
struct node num,* head, * p=head;
//int ordinal=1,remain=13;

//开辟13个节点
//在节点里存入数据num:1~13

if(p!=NULL) printf("Not NULL...\n");
printf("%d ",p->num);
for(int i=0;i<13;i++)
{
p->num=i+1;
printf("%d ",p->num);
p=p->next;
}

p=NULL;



麻烦大家帮忙看看,谢谢!
...全文
242 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
源代码大师 2021-04-26
  • 打赏
  • 举报
回复
C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html C和C++算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html
赵4老师 2021-04-20
  • 打赏
  • 举报
回复
数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633
自信男孩 2021-04-20
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
}node;

int main(void)
{
//struct node num,* head, * p=head;
struct node num, *head, *tail, *p;
//int ordinal=1,remain=13;

//开辟13个节点
//在节点里存入数据num:1~13

//if(p!=NULL) printf("Not NULL...\n");
//printf("%d ",p->num);
head = NULL;
for(int i=0;i<13;i++)
{
p = (struct node *)malloc(sizeof(struct node));
if (!p)
exit(0);
if (!head)
head = p;
else
tail->next = p;
p->num=i+1;
printf("%d ",p->num);
tail = p;
//p=p->next;
}

p->next = NULL;

p = head;
while (p) {
printf("%d ",p->num);
p = p->next;
}
printf("\n");

return 0;
}

供参考~
qzjhjxj 2021-04-19
  • 打赏
  • 举报
回复
暂停运行是指什么?参考楼主的代码修改,生成带头节点的13个节点的链表,同时往里存入1-13,供参考:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
    int num;
    struct node *next;
}node;
void main()
{
    struct node num,* head, * p,*q;
    //int ordinal=1,remain=13;
    //开辟13个节点
    //在节点里存入数据num:1~13
    head = (struct node *)malloc(sizeof(struct node));
    head->next = NULL;
    q = head;
    if(q!=NULL) printf("Not NULL...\n");
    //printf("%d ",p->num);
    for(int i=0;i<13;i++)
    {
        p = (struct node *)malloc(sizeof(struct node));
        p->num=i+1;
        p->next=NULL;
        q->next=p;
        q=p;
        printf("i=%d,%d\n",i,p->num);
        //p=p->next;
    }
    q=head->next;
    while(q){
          printf("%d\n",q->num);
          q=q->next;
    }
    //p=NULL;
    system("pause");
}
mmcanyu 2021-04-19
  • 打赏
  • 举报
回复
head是野指针

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧