file handling problem, please help

I have a data file, data.txt
1
2
3
4
5
6
1     0.011070     0.5100     0.4900     1.0211
	9	2
	11	19	8    7
2     0.021373     0.1000     0.0870     1.1332
	8	13
	6	14	5    9
and so on until n=100

The first no. is n (going 1,2,... till 100).
Now, I am having a nightmare of a time in making a C code for reading this data.
How can I make a C code to read data.txt, such that I can make the following matrices :

a[1][1]=0.011070, a[1][2]=0.5100, a[1][3]=0.4900, a[1][4]=1.0211
b[1][1]=9, b[1][2]=2
c[1][1]=11, c[1][2]=19, c[1][3]=8, c[1][4]=7

Similarly, for n=2 (4th, 5th & 6th rows)
a[2][1]=0.021373, a[2][2]=0.1000, a[2][3]=0.0870, a[2][4]=1.1332
b[2][1]=8, b[2][2]=13
c[2][1]=6, c[2][2]=14, c[2][3]=5, c[2][4]=9

and I go upto n=100.

As is clear, I want matrix a to be float, and b and c as int.

*The no. of columns of array a,b and c are same for all n.

PLEASE KINDLY HELP SOON, AM BADLY STUCK.
Regards
Alice
A good place to start would be this -> http://cplusplus.com/reference/clibrary/cstdio/

More specifically:

http://cplusplus.com/reference/clibrary/cstdio/fopen/
http://cplusplus.com/reference/clibrary/cstdio/fscanf/

A typical implementation of your program would look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//...

declare a, b, c

open file

for (i = 0 to 99)
{
    read index //and ignore it

    read a[i][0], a[i][1], a[i][2], a[i][3]

    read b[i][0], b[i][1]

    read c[i][0], c[i][1], c[i][2], c[i][3]
}

close file

//... 

EDIT: Though, why C? (just curious)

EDIT2: Another useful link -> http://www.eng.iastate.edu/efmd/cmultarray.html#scanw
Last edited on
Topic archived. No new replies allowed.