The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fscanf abey High Level Programming 4 02-14-2006 06:29 AM
fscanf() j_t_kim High Level Programming 1 03-15-2002 08:52 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-11-2002
Registered User
 

Join Date: Mar 2002
Posts: 6
fscanf()

I keep trying to use fscanf() and for some reason I can't get the syntax down and always get seg faults. I'm on a SunOS 5.5.1, and my current code looks like this:

int n1, n2, n3, n4, n5, n6;

/* open config file */
if (fileptr = fopen(filename,"r") == NULL) {
printf("couldn't open file, errno: %d\n", errno);
exit(0);
}

fscanf(fileptr, "%d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6);


(end)
######### FIRST LINE FILE LOOKS LIKE THIS #######
4500 4017 1 0 1 2

I've been trying to get past this for hours now and was hoping someone could offer some advice or explanation as to why it keeps seg faulting. THANKS!
Reply With Quote
Forum Sponsor
  #2  
Old 03-11-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,658
The bug must be elsewhere. The code you posted looks good. I tried it on hp-ux and it worked.
Reply With Quote
  #3  
Old 03-11-2002
Registered User
 

Join Date: Mar 2002
Posts: 6
OK, thanks

Thanks for checking, I'll keep looking around...
Reply With Quote
  #4  
Old 04-03-2002
Registered User
 

Join Date: Mar 2002
Location: Bangalore,Karnataka State,India
Posts: 18
I found the ANSWER

Hi,
I found the answer for your problem
Take a look at the following program :

int n1, n2, n3, n4, n5, n6;

/* open config file */
if ((fileptr = fopen(filename,"r") )== NULL) {
printf("couldn't open file, errno: %d\n", errno);
exit(0);
}

fscanf(fileptr, "%d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6);


What I did was I introduced a pair of brackets around "fileptr".
I can bet that, you won't get the error any more.

thank you,
K.S.SHARATH CHANDRA

if ((fileptr = fopen(filename,"r") )== NULL)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0