473,326 Members | 2,076 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,326 software developers and data experts.

Please help with File IO

Hello,

I have a text file I'm attempting to parse. There are about 50 fixed width
fields in each line / row. For example (shortened for brevity):

W1234Somebody East 101110001111010101
E1235Someone Else West 010111001001010101

I'm having problems pulling these fields into structures, in order to be
able to access each individually. I am currently opening as a sequential
file. Is there a better way?

My structure looks something like:

struct data{
char area[1];
char empNumber[4];
char name[16]
char region[5];
char options[20];
}

int index = 0;
data user[100];

I would like to read the entire file into memory. Please tell me if I'm
going about this the wrong way. So far after reading the file in, I'm
unable to access any individual items (ie. user[index].area) Also should
I stick with a sequential file, or should I consider binary access (seems
like it may be easier to address individual elements)?

(I don't want to include too many details here, but will be happy to provide
whatever is needed).

Thank you in advance,
Brian
Jul 22 '05 #1
2 1654
"Brian" <bk****@hotmail.com> wrote in message news:3d**************************@posting.google.c om...
Hello,

I have a text file I'm attempting to parse. There are about 50 fixed width
fields in each line / row. For example (shortened for brevity):

W1234Somebody East 101110001111010101
E1235Someone Else West 010111001001010101

I'm having problems pulling these fields into structures, in order to be
able to access each individually. I am currently opening as a sequential
file. Is there a better way?

My structure looks something like:

struct data{
char area[1];
char empNumber[4];
char name[16]
char region[5];
char options[20];
}

int index = 0;
data user[100];

I would like to read the entire file into memory. Please tell me if I'm
going about this the wrong way.
The information you provide does not permit such a conclusion.
Diagnosing "The wrong way" would have to be based on your
requirements, unstated so far. Your approach is going to present
difficulties if the format changes, but I presume you know that.
So far after reading the file in, I'm
unable to access any individual items (ie. user[index].area)
I cannot translate "I'm unable to access" into a familiar fact.
Do you mean "I can access individual fields but their values
differ from what I expected."? Or is it something else? If
the former: What did you get? What did you expect? And
why did you expect it? If the latter, please elaborate.
Also should
I stick with a sequential file, or should I consider binary access (seems
like it may be easier to address individual elements)?
I have not heard of "sequential file" in connection with the
standard C or C++ libraries. If you are distinguishing that
from files opened in binary mode, then, from the fact that
you claim to be dealing with a "text file", it is clear that you
do not want binary mode. The "not binary" mode is often
known as "text mode". Files are considered a sequential
series of bytes whether binary or not.
(I don't want to include too many details here, but will be happy to provide
whatever is needed).
It would probably help to see the call you use to read in
the file, together with enough data to know what values
the call parameters have.

You have given few clues as to how records are separated
in your input file. Are line-ends used for that? If so, your
attempt to blast in a whole series of records fails to account
for the space taken by the record separators. If not, your
example is misleading.
Thank you in advance, Good luck.
Brian

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 22 '05 #2
Hi Larry,

I just posted my code and a sample of the data as a follow-up to my
other post: "Best way to access this File?". I do apologize for the
post - I realize I didn't do a good job in posing the question.

Thanks!
Brian

"Larry Brasfield" <do***********************@hotmail.com> wrote in message news:<BM***************@news.uswest.net>...
"Brian" <bk****@hotmail.com> wrote in message news:3d**************************@posting.google.c om...
Hello,

I have a text file I'm attempting to parse. There are about 50 fixed width
fields in each line / row. For example (shortened for brevity):

W1234Somebody East 101110001111010101
E1235Someone Else West 010111001001010101

I'm having problems pulling these fields into structures, in order to be
able to access each individually. I am currently opening as a sequential
file. Is there a better way?

My structure looks something like:

struct data{
char area[1];
char empNumber[4];
char name[16]
char region[5];
char options[20];
}

int index = 0;
data user[100];

I would like to read the entire file into memory. Please tell me if I'm
going about this the wrong way.


The information you provide does not permit such a conclusion.
Diagnosing "The wrong way" would have to be based on your
requirements, unstated so far. Your approach is going to present
difficulties if the format changes, but I presume you know that.
So far after reading the file in, I'm
unable to access any individual items (ie. user[index].area)


I cannot translate "I'm unable to access" into a familiar fact.
Do you mean "I can access individual fields but their values
differ from what I expected."? Or is it something else? If
the former: What did you get? What did you expect? And
why did you expect it? If the latter, please elaborate.
Also should
I stick with a sequential file, or should I consider binary access (seems
like it may be easier to address individual elements)?


I have not heard of "sequential file" in connection with the
standard C or C++ libraries. If you are distinguishing that
from files opened in binary mode, then, from the fact that
you claim to be dealing with a "text file", it is clear that you
do not want binary mode. The "not binary" mode is often
known as "text mode". Files are considered a sequential
series of bytes whether binary or not.
(I don't want to include too many details here, but will be happy to provide
whatever is needed).


It would probably help to see the call you use to read in
the file, together with enough data to know what values
the call parameters have.

You have given few clues as to how records are separated
in your input file. Are line-ends used for that? If so, your
attempt to blast in a whole series of records fails to account
for the space taken by the record separators. If not, your
example is misleading.
Thank you in advance,

Good luck.
Brian

Jul 22 '05 #3

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

Similar topics

1
by: Dan | last post by:
Hello, I am trying to read and write to an Excel file via my Java applet. I have done so successfully on several simple Excel files that simply had data cells without many complicated equations...
3
by: JGBNS via DotNetMonster.com | last post by:
Hi, I am new to this forumand I apologize as i am not a .net programmer but we have a program being developed by a .net programmer. Nowwe have run into an ftp snag and I think it is part ftp and...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
25
by: n3crius | last post by:
hi, i just got a web host with asp.net , seemed really cool. aspx with the c# or vb IN the actual main page run fine, but when i use codebehind and make another source file ( a .cs) to go with...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.