By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

How can-i read integers from a file, where the first line contains unknown elements?

P: 3
A set of natural numbers is given. Generate all the subsets of this set joined by alternating +and -operators which
sum up to exactly S. .
I/O description. Input: enumeration of elements in the set, on one line, then sum on one line e.g.

1 3 5 7 2 6
0

Output: enumeration of elements resulting in the given sum, e.g.

1-3+2
1+3-6
5-7+2
1+5-6

First i have to read from the file the first line`s elements, could enyone help me?
Dec 9 '10 #1
Share this Question
Share on Google+
4 Replies


P: 9
Read a whole line split it with white space chars. Now you get set of word. Parse each word to get integer.




-RajX
Dec 9 '10 #2

P: 3
I searched on the internet for many codes, but it does't work. Could you give me some code? How can i read each line, and split them?
Dec 9 '10 #3

100+
P: 1,059
use fgets function to read line from file

do rest by yourself
Dec 10 '10 #4

P: 3
i`ve red each line as a string, but now how can-i split it at space characters? any c code? pls
Dec 10 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.