![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| read a file wich fscanf() in a function | cdbug | High Level Programming | 2 | 10-06-2008 08:46 AM |
| To read and separate number and words in file and store to two new file using shell | kamakshi s | Shell Programming and Scripting | 2 | 06-26-2008 07:39 AM |
| script to Read Error,jbase,voilation,segmentation words from a file | Mujtaba khan | Shell Programming and Scripting | 3 | 03-30-2008 01:19 PM |
| how to read all the unique words in a text file | aditya.ece1985 | Shell Programming and Scripting | 5 | 11-30-2007 02:26 AM |
| Read words from file and create new file using K-shell. | bsrajirs | Shell Programming and Scripting | 4 | 06-01-2007 12:15 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
fscanf: read words from file
Hi
I have a file like that: 1 2 3 4 5 6 7 8 and I want print on stdout: 1 3 8 in other words i want choose what print out. I was thinking to use fscanf as: Code:
fscanf(file_in,"%d %d %d",&a, &b,&c); 1 2 3 Is there a solution using fscanf to obtain my purpose? Thanks D ---------- Post updated at 11:08 AM ---------- Previous update was at 10:51 AM ---------- hi I solved it. it enough to insert a format type indicator, something like: fscanf(file_in,"%d %*1hd %d ",&a, &b,&c) here the references fscanf - C++ Reference. D. |
|
||||
|
scanf is generally considered unsafe, as is fscanf for similar reasons.
You're much better off learning how to use fgets and sscanf to do your work. fscanf will continue to read %d from your stream, skipping whitespace and stopping when it can't read another one, so you could have read them in a loop, discarding the ones you didn't want. |
![]() |
| Bookmarks |
| Tags |
| file, fscanf |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|