LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2002, 08:21 PM   #1
purpleburple
Member
 
Registered: Jun 2002
Location: USA
Distribution: Slackware8.1
Posts: 332

Rep: Reputation: 30
why am I getting 'segmentation fault' with this ?


Hi. The following gives me a segmentation fault and I don't understand why ..

#include <stdio.h>

int main(void)
{

char text[200];

puts("Enter some text and press <ENTER>");

fgets(text, 200, stdin);

printf("You entered %s\n");

return 0;

}

any help appreciated .
thanks
 
Old 09-04-2002, 01:03 AM   #2
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
will this help in printf
printf("You entered %s\n",text);
 
Old 09-04-2002, 01:05 AM   #3
kwigibo
Member
 
Registered: Apr 2002
Posts: 53

Rep: Reputation: 15
also just as a safety feature if you want to be able to read in 200 characters make your array 201 characters long, just a safety thing you know
 
Old 09-04-2002, 02:56 AM   #4
purpleburple
Member
 
Registered: Jun 2002
Location: USA
Distribution: Slackware8.1
Posts: 332

Original Poster
Rep: Reputation: 30
oh .... how stupid of me .... thanks neo777
 
Old 09-04-2002, 07:50 PM   #5
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
Wow, I was degraded from 5times7 to 3times7, tahnks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 05:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 10:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 12:13 PM
Segmentation fault tejas15_10 Programming 9 06-20-2005 10:12 AM
Segmentation fault santhosh_o Programming 3 10-26-2004 06:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:52 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