Sponsored Content
Full Discussion: fscanf: read words from file
Top Forums Programming fscanf: read words from file Post 302328324 by Dedalus on Wednesday 24th of June 2009 05:08:25 AM
Old 06-24-2009
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);

but in this way i get:
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read words from file and create new file using K-shell.

Hi All, Please help me in creating files through K-shell scripts. I am having one file in this format. OWNER.TABLE_NAME OWNER.TABLE_NAME1 OWNER1.TABLE_NAME OWNER1.TABLE_NAME1 I want to read the above file and create new file through k shell script. The new file should looks like this.... (4 Replies)
Discussion started by: bsrajirs
4 Replies

2. Shell Programming and Scripting

how to read all the unique words in a text file

How can i read all the unique words in a file, i used - cat comment_file.txt | /usr/xpg6/bin/tr -sc 'A-Za-z' '/012' and cat comment_file.txt | /usr/xpg6/bin/tr -sdc 'A-Za-z' '/012' but they didnt worked..... (5 Replies)
Discussion started by: aditya.ece1985
5 Replies

3. Shell Programming and Scripting

script to Read Error,jbase,voilation,segmentation words from a file

Hi, i need a script to find words "error,jbase,voilation,segmentation" from a file(verify.txt) and if got any of the above words then send an email and if wont find any then execute the cron job. every time it read file verify.txt it must first clear the previous data in the file . Kindly... (3 Replies)
Discussion started by: Mujtaba khan
3 Replies

4. Shell Programming and Scripting

To read and separate number and words in file and store to two new file using shell

hi, I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting. Please help me out for this. Regards S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies

5. Programming

read a file wich fscanf() in a function

I use fopen, fscanf, fclose to read a file. It can work well. since many files should be read, a function is created with the same code. But in the function, fscanf can not work well. for example, the first line of the the file is: > filename but the fscanf will give: 207/23/eee/34 it appears... (2 Replies)
Discussion started by: cdbug
2 Replies

6. Shell Programming and Scripting

Splitting Concatenated Words in Input File with Words from a Master File

Hello, I have a complex problem. I have a file in which words have been joined together: Theboy ranslowly I want to be able to correctly split the words using a lookup file in which all the words occur: the boy ran slowly slow put child ly The lookup file which is meant for look up... (21 Replies)
Discussion started by: gimley
21 Replies

7. Shell Programming and Scripting

Splitting concatenated words in input file with words from the same file

Dear all, I am working with names and I have a large file of names in which some words are written together (upto 4 or 5) and their corresponding single forms are also present in the word-list. An example would make this clear annamarie mariechristine johnsmith johnjoseph smith john smith... (8 Replies)
Discussion started by: gimley
8 Replies

8. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

9. UNIX for Beginners Questions & Answers

Shell - Read a text file with two words and extract data

hi I made this simple script to extract data and pretty much is a list and would like to extract data of two words separated by commas and I would like to make a new text file that would list these extracted data into a list and each in a new line. Example that worked for me with text file... (5 Replies)
Discussion started by: dandaryll
5 Replies

10. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies
FSCANF(3)								 1								 FSCANF(3)

fscanf - Parses input from a file according to a format

SYNOPSIS
mixed fscanf (resource $handle, string $format, [mixed &$...]) DESCRIPTION
The function fscanf(3) is similar to sscanf(3), but it takes its input from a file associated with $handle and interprets the input according to the specified $format, which is described in the documentation for sprintf(3). Any whitespace in the format string matches any whitespace in the input stream. This means that even a tab in the format string can match a single space character in the input stream. Each call to fscanf(3) reads one line from the file. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $format - The specified format as described in the sprintf(3) documentation. o $... - The optional assigned values. RETURN VALUES
If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference. EXAMPLES
Example #1 fscanf(3) Example <?php $handle = fopen("users.txt", "r"); while ($userinfo = fscanf($handle, "%s %s %s ")) { list ($name, $profession, $countrycode) = $userinfo; //... do something with the values } fclose($handle); ?> Example #2 Contents of users.txt javier argonaut pe hiroshi sculptor jp robert slacker us luigi florist it SEE ALSO
fread(3), fgets(3), fgetss(3), sscanf(3), printf(3), sprintf(3). PHP Documentation Group FSCANF(3)
All times are GMT -4. The time now is 06:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy