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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tta aaa
    New Member
    • Dec 2010
    • 3

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

    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?
  • Raj K
    New Member
    • Dec 2010
    • 9

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




    -RajX
    Last edited by Niheel; Dec 9 '10, 09:03 PM.

    Comment

    • tta aaa
      New Member
      • Dec 2010
      • 3

      #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?

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        use fgets function to read line from file

        do rest by yourself

        Comment

        • tta aaa
          New Member
          • Dec 2010
          • 3

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

          Comment

          Working...