LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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
 
LinkBack Search this Thread
Old 03-06-2006, 06:36 AM   #1
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Rep: Reputation: 30
using fgets/sscanf wiht c


im having trouble trying to get fgets and sscanf to work. im getting a segmentation fault right at the sscanf line of this code... can anyone tell me the reason?


Code:
int main() {
        int integ;
        char line[400];

        printf("Enter an integer: ");
        fgets(line, sizeof(line), stdin);
        sscanf(line,"%d",&integ);
        printf("%d",&integ);
        return 0;
}


NEVERMID, FOUND MY PROBLEM, PLEASE REMOVE!!

Last edited by true_atlantis; 03-06-2006 at 06:46 AM.
 
Old 03-06-2006, 08:09 AM   #2
msyss
LQ Newbie
 
Registered: Mar 2006
Distribution: Arch Linux
Posts: 12

Rep: Reputation: 0
That's weird. I compiled it on my machine, and it works.

Could you tell which compiler you are using?
 
Old 03-06-2006, 12:15 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
So what was the problem (besides the "&integ" in your "printf()" - which *shouldn't* cause a segv)?
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
another sscanf Q jnusa Programming 10 10-27-2004 02:33 AM
Garbage value dumped by sscanf sheenak Programming 2 05-27-2004 11:55 PM
fgets h/w Programming 23 12-21-2003 06:20 PM
fgets vs gets cxel91a Programming 2 12-01-2003 12:36 PM
sscanf help jpc82 Programming 8 11-04-2003 02:01 PM


All times are GMT -5. The time now is 05:43 AM.

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
Open Source Consulting | Domain Registration