需要细分错误方面的帮助

编程入门 行业动态 更新时间:2024-10-21 02:47:37
本文介绍了需要细分错误方面的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码,可以运行.但是,当我运行它时,它总是说存在段故障".我在Ubuntu Linux上运行它.我不知道为什么会发生,如果您知道,请告诉我,谢谢. :)

This is my code, it can run. But when i run it it always says "There is segment fault". I run it on Ubuntu Linux. I don''t know why it happens, if you know please tell me, thanks. :)

/* Copyright( c ), 2010, @ linux laboratory in xiyou. All rights reserved. File name: front_list.c. Programmer''s name: Harry . wei. Start time: 5, 31. Finish time: 5,31. Programme''s introduction: use front list to init the list. Modify time: Modify programmer: Modify introduction: */ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef struct Mystruct_Node { int data; struct Mystruct_Node * next; }*Linklist, List; int main( void ) { printf( "111111" ); Linklist l; Linklist s; char c; // int flag = 1; l -> next = NULL; printf( "Please enter characters:" ); printf( "11111\n" ); while( true ) { c = getchar(); if( c != ''$'' ) { s = ( Linklist )malloc( sizeof( List ) ); s -> data = c; s -> next = l -> next; // First, s->next get the NULL value from l->next. l -> next = s; } else { break; } } l = l -> next; while( l -> next != NULL ) { printf( "%c", l -> data ); l = l -> next; } return( false ); }

推荐答案

'') { s =(链接列表)malloc(sizeof(List)); s->数据= c; s->下一个= l->下一个; //首先,s-> next从l-> next获取NULL值. l-> next = s; } 别的 { 休息; } } l = 1->下一个; while(l-> next!= NULL) { printf(%c",l-> data); l = 1->下一个; } return(false); } '' ) { s = ( Linklist )malloc( sizeof( List ) ); s -> data = c; s -> next = l -> next; // First, s->next get the NULL value from l->next. l -> next = s; } else { break; } } l = l -> next; while( l -> next != NULL ) { printf( "%c", l -> data ); l = l -> next; } return( false ); }

Linklist l; //Uninitilazed pointer to List structure Linklist l = (Linklist)malloc(sizeof(List));//Initialized pointer to List structure (heap) List l; //Initialized List structure (stack)

实际上,分段错误是内存错误.错误出现..pls一旦确认您的代码.. Hai actually Segmentation Fault is comming to Memory fault .. ur parametesr are not allocate memmory thet time its error is comming ..pls once ckeck ur code..

更多推荐

需要细分错误方面的帮助

本文发布于:2023-11-28 15:29:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!