本文介绍了需要细分错误方面的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,可以运行.但是,当我运行它时,它总是说存在段故障".我在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..
更多推荐
需要细分错误方面的帮助
发布评论