473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1478

"srikanth" <sr************ *******@gmail.c om> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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
6236
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. Only when the buffer becomes full does it resume execution. Here's my test code for reading from a pipe: //(compiled with g++ -std=c++98)...
1
1798
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 sql database. Here the xml file which has to be read. <transactions> <smssent time="10:30" subsid="12" dest="07951998960"
2
16123
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 fread() or the Visual C specific(?) read() they return that the number of bytes read equals the number of bytes requested, however all of the bytes...
3
3486
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 chars, i can read it in 50 chars for twice or 10 chars in ten times or 25 chars for 4 times...like this. Here, file size, i.e 100 chars is known to...
6
5455
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 differently than Java does. I suspected an endianess problem and tried out ntohl/htonl but it doesn't help. Any clues?
9
9849
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 should loop 15,870,080 times. The code is: newprogram.cpp =============
21
626
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() { ifstream inFile;
6
3515
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 to an old program that I wrote in delphi and it's a good opportunity to start with c++.
2
2832
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 wireless where I'm working could just be ungodly slow-- which it is.) Is reading a file much more resource/processor intensive than, say, including a...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.