How to read the file given below in C and print the numbers in an array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aeroranger
    New Member
    • Jul 2010
    • 2

    How to read the file given below in C and print the numbers in an array?

    Hi all,

    My file has characters and numbers in the format given below:

    #
    1
    2
    3
    4
    5
    #
    7
    10
    0
    -5
    8

    I would like to read this file in C. Now everytime '#' appears it has to read the numbers below '#' and put them in an array say x[i][j]. It should increment 'j' everytime the program comes across an integer in the file. Everytime it comes across a '#', it has to make j=0; and increment 'i' by 1. For the input given above using a file, the numbers should be put in an array as given below:

    #
    1 i=0 j=0
    2 i=0 j=1
    3 i=0 j=2
    4 i=0 j=3
    5 i=0 j=4
    #
    7 i=1 j=0
    10 i=1 j=1
    0 i=1 j=2
    -5 i=1 j=3
    8 i=1 j=4

    Thanks in advance for your replies!!!
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Have you started writing anything for this?
    We can help you with ideas and not code.

    Raghu

    Comment

    • aeroranger
      New Member
      • Jul 2010
      • 2

      #3
      Originally posted by gpraghuram
      Have you started writing anything for this?
      We can help you with ideas and not code.

      Raghu
      yes, i have been able to write the code for sigle row of data following '#' . I am facing difficulty in several such series of rows.

      Aeroranger

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        I don't know what your difficulties are, but perhaps it would help to take a look at Arrays Revealed.

        Comment

        Working...