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

Discussion in 'C Programming' started by srikanth, Jun 28, 2005.

  1. srikanth

    srikanth Guest

    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
     
    srikanth, Jun 28, 2005
    #1
    1. Advertising

  2. srikanth

    Mike Wahler Guest

    "srikanth" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Jun 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    521
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  2. =?Utf-8?B?bWF2cmlja18xMDE=?=

    Forms Authentication Fails some times and not some times???

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 28, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    497
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 28, 2006
  3. Sam Iam
    Replies:
    0
    Views:
    455
    Sam Iam
    Jan 31, 2004
  4. Yasin cepeci
    Replies:
    1
    Views:
    309
    Alexey Smirnov
    Jun 4, 2007
  5. nigel stephens

    controls fail to be filled correctly 1 out of 4 times

    nigel stephens, Dec 20, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    96
    nigel stephens
    Dec 20, 2005
Loading...

Share This Page