How do i read this file line by line & count the length ? Please help.
numDim: 4
dim: 128 128 128 1
fov: 26.88 26.88 26.88 1.000
interval: 0.21 0.21 0.21 1.0
dataType: word
sdtOrient: ax
endian: ieee-le
How do i read this file line by line & count the length ? Please help.
numDim: 4
dim: 128 128 128 1
fov: 26.88 26.88 26.88 1.000
interval: 0.21 0.21 0.21 1.0
dataType: word
sdtOrient: ax
endian: ieee-le
If you just want to:
you can use the functions:
fopen
to open the filefgetl
to read (within a loop) each linelength
to evaluate the length of each linefclose
to close the input file at the endyou should also use a counter to count the number of lines.
To store the line you can use a
cellarray
This is a possible implementation:
In case you want to read the input file and store the "numeric" values in an array, in addition to the above mentioned functions you can use:
you can then use a struct to save the input; this allows you to dynamically create the fild of the struct assigning them, as name, the first string of each line.
A
switch
can be used to identify the specific line and scan the data accordingly.A possible impleentation can be:
This create the following output struct:
Hope this helps,
Qapla'