LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-26-2004, 05:33 AM   #1
santhosh_o
LQ Newbie
 
Registered: Oct 2004
Location: India
Posts: 6

Rep: Reputation: 0
Segmentation fault


hai everybody,
I worte a program and it does prints the output and after that it showed me segmentation fault error. could anybody help me out.

program is as follows:


#include <stdio.h>




int main()
{
int i,j;
FILE *f;
char *s1,*s2;


f=fopen("junk","w");

scanf("%s",s1);
if (!f)
return 1;
fwrite(&s1,sizeof(s1),1,f);
fclose(f);


f=fopen("junk","r");
if (!f)
return 1;
fread(&s2,sizeof(s1),1,f);
printf("%s\n",s2);

fclose(f);
printf("\n");

return 0;
}
 
Old 10-26-2004, 05:38 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Quote:
char *s1,*s2;

scanf("%s",s1);
You can't do that. s1 needs to point to some reserved space in which to store the string. Right now scanf() is storing the input string into a random location in memory. You're lucky it's even getting past that.

You can either make it like char s1[50]; or keep your declaration the same and malloc() some memory.
 
Old 10-26-2004, 05:42 AM   #3
santhosh_o
LQ Newbie
 
Registered: Oct 2004
Location: India
Posts: 6

Original Poster
Rep: Reputation: 0
can u help me in this

Thank you , I will try that out.

can u help me in this.

Now I am trying to create own login screen and authentication. Actually my login screen should come first and after that only the gdm login screen should appear. I have created my login screen using gtk+. I have redhat linux 9(shrike) and kernel version is 2.4.20-6smp. My default runlevel is 5. I am trying this for past one week but i am not getting the my login screen first when linux boots up. Please help me in this.
 
Old 10-26-2004, 05:45 AM   #4
santhosh_o
LQ Newbie
 
Registered: Oct 2004
Location: India
Posts: 6

Original Poster
Rep: Reputation: 0
thankyou

can u help me in this ( post #)

Thank you , I will try that out.

can u help me in this.

Now I am trying to create own login screen and authentication. Actually my login screen should come first and after that only the gdm login screen should appear. I have created my login screen using gtk+. I have redhat linux 9(shrike) and kernel version is 2.4.20-6smp. My default runlevel is 5. I am trying this for past one week but i am not getting the my login screen first when linux boots up. Please help me in this.
 
  


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 04:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 09:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 11:13 AM
Segmentation fault tejas15_10 Programming 9 06-20-2005 09:12 AM
Segmentation fault tejas15_10 Linux - Newbie 1 06-14-2005 04:44 AM


All times are GMT -5. The time now is 06:29 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration