关于VS2019调试问题:进程已退出,代码为-1073741819(已解决)

详情:上一篇发了这个进程问题,在我翻阅了《c语言程序设计第四版》和《算法与数据结构》两本书对照代码加上调试终于找到了解决方法

解决方法:
首先找到项目的源文件右击找到属性

然后选择从生成中排除选择是!

重新生成解决方案,发现代码问题:

之前的代码:
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h>
//创建链表 struct linknode { int data; struct linknode* next; }; //初始化链表->创建一个空链表
struct linknode* init_list() { //创建头结点 struct linknode* head = malloc(sizeof(
struct linknode)); head->data = 0; head->next = NULL; //创建尾节点 struct linknode* p
= head; //获得用户输入 int nodedata = 0; while (1) { printf("请输入值(输入等于0的值退出):");
scanf_s("%d", &nodedata); if (nodedata == 0) { break; } //创建新结点 struct linknode*
newnode= malloc(sizeof(struct linknode)); newnode->data = nodedata; newnode->
next= NULL; //把新结点插入链表中 p->next = newnode; //更新尾指针 p = newnode; } return head;
//返回头节点即返回列表 } //在old_data值之后插入一个new_data值(在原来的结点后面串联一个新的结点) void addlist(struct
linknode* head, int old_data, int new_data); //删除数据 void dellist(struct
linknode* head, int deldata); //遍历打印链表 void showlist(struct linknode* head) {
/*if (head == NULL) { return; }*/ struct linknode* p = head->next;
//创建尾结点让他指向第一个空头结点的地址域 while (p != NULL) { printf("%d", p->data); p = p->next; }
} //清空链表 void clearlist(struct linknode* head); //摧毁链表 void destory_list(struct
linknode* head); int main() { struct linknode *head = init_list(); showlist(&
head); return 0; }
对照书修改后:
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h>
#define LEN sizeof(struct linknode) //创建链表 struct linknode { int data; struct
linknode* next; }; //初始化链表->创建一个空链表 struct linknode* init_list() { //创建头结点
struct linknode* head =(struct linknode*) malloc(LEN); head->data = 0; head->
next= NULL; //创建尾节点 struct linknode* p = head; //获得用户输入 int nodedata = 0; while
(1) { printf("请输入值(输入等于0的值退出):"); scanf_s("%d", &nodedata); if (nodedata == 0) {
break; } //创建新结点 struct linknode* newnode = (struct linknode*)malloc(LEN);
newnode->data = nodedata; newnode->next = NULL; //把新结点插入链表中 p->next = newnode;
//更新尾指针 p = newnode; } return head;//返回头节点即返回列表 }
//在old_data值之后插入一个new_data值(在原来的结点后面串联一个新的结点) void addlist(struct linknode* head
, int old_data, int new_data); //删除数据 void dellist(struct linknode* head, int
deldata); //遍历打印链表 void showlist(struct linknode* head) { /*if (head == NULL) {
return; }*/ struct linknode* p = head->next;//创建尾结点让他指向第一个空头结点的地址域 while (p !=
NULL) { printf("%d\t", p->data); p = p->next; } } //清空链表 void clearlist(struct
linknode* head); //摧毁链表 void destory_list(struct linknode* head); int main() {
struct linknode* head = init_list(); showlist(head); return 0; }
增加了宏定义
修改了
struct linknode* newnode = (struct linknode*)malloc(LEN);

最后我们保存修改,移除c文件再重新导入一遍c文件或者可以重新启动VS2019,调试!

成功:

技术
今日推荐
PPT
阅读数 121
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信