473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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

Nov 15 '05 #1
1 1470

"srikanth" <sr*******************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: inkapyrite | last post by:
Hi all. I'm using ifstream to read from a named pipe but i've encountered an annoying problem. For some reason, the program blocks on reading an ifstream's internal buffer that's only half-filled....
1
by: Sunil Pathi | last post by:
Thanks in Advance I have a XML file which is read from a .aspx page. I need to read through all the elements, find the values of them and pass them on to the stored procedure which updates the...
2
by: JS | last post by:
Hello all! I have come on to a problem for which I am not able to find a solution searching the web. What I am trying to do is reading a log-file with a size of 1.3 GB. When reading it using...
3
by: syntax | last post by:
hi, i want to read a file using fread() in equal chunks through a for loop so that at the last call i dont get error..which way, i should read it? let me give an example, suppose i have 100...
6
by: sbalko | last post by:
Hi, I am trying to read Java-floats (IEEE 754 encoding) stored in a binary file from C (gcc on linux/i386, more specifically). Unfortunately, C seems to expect floats to be stored somewhat...
9
by: Use*n*x | last post by:
Hello, I have a binary file (image file) and am reading 4-bytes at a time. The File size is 63,480,320 bytes. My assumption is that if I loop through this file reading 4 bytes at a time, I...
21
by: Naya | last post by:
Hello, everyone!!! Well, I have a situation here. I am trying to read this data from a file, but the wrong values keep spitting out at me. Here's what I mean: Program: int main() {...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.