reading from a file, some times values in file may not be filled

S

srikanth

hi,

I have one file it filled with some values in rows/colums.
some times, some variables (in a particular row& column) may not be
filled. depending on the kind its filled i will go for defferent kind
of operations in my C-programm.
with fgets and sscanf, i can get values in one line, but some times
some particular row&column may be not filled. then how can my programm
knows its not filled.
means it cant take empty space as NaN(not a number), just that not
filled variable takes next row&colum value as its value. or some thing
other happens.
So could any one tell how this can be solved..
my file looks like this....

position_1 initial_vel Final_vel
Time_1 10 12

Time_2 25

Time_3 40 30

Time_4 50

at time_1 final_vel is not filled , so do calculation in one
type.
and at time_2 inital_vel& Final_vel is not filled so do
calculation in another way....etc

and other person may change this above table file in other way..like
below

position_1 initial_vel Final_vel
Time_1 10

Time_2 25 30

Time_3 40

Time_4 50

So to read this file whether value is enter or not for
particular field, how can i do??

Thank you,

srikanth
 
M

Mike Wahler

srikanth said:
hi,

I have one file it filled with some values in rows/colums.
some times, some variables (in a particular row& column) may not be
filled. depending on the kind its filled i will go for defferent kind
of operations in my C-programm.
with fgets and sscanf, i can get values in one line, but some times
some particular row&column may be not filled. then how can my programm
knows its not filled.
means it cant take empty space as NaN(not a number), just that not
filled variable takes next row&colum value as its value. or some thing
other happens.
So could any one tell how this can be solved..
my file looks like this....

position_1 initial_vel Final_vel
Time_1 10 12

Time_2 25

Time_3 40 30

Time_4 50

at time_1 final_vel is not filled , so do calculation in one
type.
and at time_2 inital_vel& Final_vel is not filled so do
calculation in another way....etc

and other person may change this above table file in other way..like
below

position_1 initial_vel Final_vel
Time_1 10

Time_2 25 30

Time_3 40

Time_4 50

So to read this file whether value is enter or not for
particular field, how can i do??

Possibilities:
1: Fixed-length fields:
Define fixed lengths for your 'fields' (columns),
and for those fields which need to be 'empty' store
spaces (or some other character you define to mean
'empty') in them.

2: Special flag value:
Invent some token, otherwise unused by your
data, which will specifically mean 'emtpy', e.g. "[EMPTY]"
or some such.

3. Delimiters:
Invent some token (typically a single character), otherwise
unused by your data, which which delimit your fields. Two
adjacent such tokens with no intervening characters would
indicate that the surrounded filed is empty. A common choice
is a comma.

4: Combine items 2 and 3.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top