![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
The bug must be elsewhere. The code you posted looks good. I tried it on hp-ux and it worked.
|
|
#3
|
|||
|
|||
|
OK, thanks
Thanks for checking, I'll keep looking around...
|
|
#4
|
|||
|
|||
|
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) |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|