LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-20-2005, 03:52 AM   #1
ramakrishna sura
LQ Newbie
 
Registered: Dec 2005
Posts: 2

Rep: Reputation: 0
programming-segmentation fault(sprintf)


Hi everybody,
Iam new to linux. I was doing networking programming. There was a program in 6th chapter of unix network programming by richard stevens that prints host info using gethostbyname() function.I typed the as it is and compiled and ran it.
It is printing info correctly if given host is there but giving segmentation fault if given host is not there.

the sprintf() function of host_err_string() (page 730 of richard stevens) is giving that error. why?

regards
Ramakrishna sura
 
Old 12-20-2005, 04:12 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
It's probably giving a segmentation fault because you're trying to print a variable
that hasn't been initialized properly (that isn't defined).
In doing so, it accesses (accidentally) a piece of memory that belongs to a different program,
causing the segmentation fault.

Simply said, check the code. See what gets printed and check if it is always defined (always has a value).
I don't have the Richard Stevens book, so I can't really help you any further.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
segmentation fault pippet Programming 4 01-24-2005 01:02 AM
segmentation fault itywygms Linux - Newbie 10 09-19-2004 08:25 PM
Segmentation fault.... lokizen Linux - Newbie 7 09-14-2004 12:40 AM
Segmentation Fault redhatnoob Linux - Software 3 11-13-2003 02:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration