473,327 Members | 1,976 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,327 software developers and data experts.

Selective reading of a file?

Hi all!

A quick question to which i'm not sure if there is an answer without changing all my code, which i'm not going to do at this point :p... i'm inputting data to a struct, and a vector simultanously from a file...

My notepad file looks like this;

RECORD1 LENGTH
RECORD2 LENGTH
CABINET1
RECORD3 LENGTH
RECORD4 LENGTH
CABINET2
RECORD5 LENGTH
RECORD6 LENGTH
CABINET3

The cabinets hold the records above them.

So when i'm inputting the data from the file, i have got a while(!file.eof) which goes through all the notepad file, and then i'm looping with a for loop to copy the first 2 lines into the struct (linked list)... and then dropping down and copying the next line into the vector.

Ideally I want this dynamic... so I can have different records inputting into different cabinets... is there any command so say if I was to put a special character into my notepad file that it would recognise this and drop out of a loop or something? E.G...

while(!file.eof)
{

while(!file.(not @ character))
{
copy to STRUCT;
}
copy to VECTOR;
}

With me?

I know i've gone about this the wrong way i'm only polishing up (ive accepted I suck ).... so any advice would be appreciated
Apr 14 '07 #1
5 2367
Savage
1,764 Expert 1GB
Hi all!

A quick question to which i'm not sure if there is an answer without changing all my code, which i'm not going to do at this point :p... i'm inputting data to a struct, and a vector simultanously from a file...

My notepad file looks like this;

RECORD1 LENGTH
RECORD2 LENGTH
CABINET1
RECORD3 LENGTH
RECORD4 LENGTH
CABINET2
RECORD5 LENGTH
RECORD6 LENGTH
CABINET3

The cabinets hold the records above them.

So when i'm inputting the data from the file, i have got a while(!file.eof) which goes through all the notepad file, and then i'm looping with a for loop to copy the first 2 lines into the struct (linked list)... and then dropping down and copying the next line into the vector.

Ideally I want this dynamic... so I can have different records inputting into different cabinets... is there any command so say if I was to put a special character into my notepad file that it would recognise this and drop out of a loop or something? E.G...

while(!file.eof)
{

while(!file.(not @ character))
{
copy to STRUCT;
}
copy to VECTOR;
}

With me?

I know i've gone about this the wrong way i'm only polishing up (ive accepted I suck ).... so any advice would be appreciated
Hi,
how abot something like:

rRECORD1 LENGTH
rRECORD2 LENGTH
cCABINET1

and then something like:

Expand|Select|Wrap|Line Numbers
  1. char string[80];
  2. while(!file.eof)
  3. {
  4.         //Use here fgets to read in a line.
  5.         if(string[0]=="r") copy to STRUCT;
  6.         else copy to VECTOR;
  7. }
Savage
Apr 14 '07 #2
I've had a mess about with the above, but haven't had much success :(

It's saying ISO C++ forbids comparison between pointer and integer, pointing at line... > if(string[0]=="r") :s

I'm guessing this is because string[0] isn't actually pointing at anything, just a empty value. How do I make the new string i've made equal to whats in the file, would I need to recode it so it was an input stream of some sort ? :s

Cheers,

Steve
Apr 14 '07 #3
Savage
1,764 Expert 1GB
I've had a mess about with the above, but haven't had much success :(

It's saying ISO C++ forbids comparison between pointer and integer, pointing at line... > if(string[0]=="r") :s

I'm guessing this is because string[0] isn't actually pointing at anything, just a empty value. How do I make the new string i've made equal to whats in the file, would I need to recode it so it was an input stream of some sort ? :s

Cheers,

Steve
Sorry,I went wrong.

Instaed of fgets use read like:
Expand|Select|Wrap|Line Numbers
  1. read(file,&string,80);
and when testing in if expression use ' ' isntead of " ".


Savage
Apr 15 '07 #4
JosAH
11,448 Expert 8TB
Sorry,I went wrong.

Instaed of fgets use read like:
Expand|Select|Wrap|Line Numbers
  1. read(file,&string,80);
and when testing in if expression use ' ' isntead of " ".


Savage
Don't do that. The read function will always attempt to read 80 bytes. The
fgets function was fine, i.e. it reads lines which can be variable length.

kind regards,

Jos
Apr 15 '07 #5
OP, It's not that you're a bad programmer. These troubles you're having are why people like databases to hold data. Of course, for your needs using a database would be overkill. So, your code will look a little funky, but that's the price you pay for the simplicity of a text file.
Apr 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike Connor | last post by:
I am having trouble getting Conditional Folder creation & File insertion to work using VS .Net in a Deployment Project for a C# app. I am displaying a generic Textbox Dialog under the User...
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
16
by: Lyle Fairfield | last post by:
There is an MS-SQL table named Bugs_Comments_and_Suggestions. There is a form named Bugs_Comments_and_Suggestions. To allow John Doe to use this form, we GRANT him LOGIN and ACCESS permissions...
6
by: max(01)* | last post by:
hi. i want to examine preprocessed source which only has certain macros expanded, for example i would like to have: #include <stdio.h> #include "other.c" int main() { ... }
1
by: Solitus | last post by:
I have databinding problem with a repeater <ItemTemplate> <tr> <!-- fixed content --> </tr> <tr> <!-- optional content --> </tr> </ItemTemplate>
10
by: Gary Jefferson | last post by:
Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B', and each module has its own logger, created with: module1logger = logging.getLogger('project.A') and module2logger =...
4
by: alex.hatzisavas | last post by:
Dear all, I'm trying to do a selective deletion from an 'Archive' table based on dates. Here is the setup: Table 'Archive' has a date field ( ). Another table ('Cutoffs') defines the Low...
0
by: arindams | last post by:
I've a form where an webrowser contains a html file. I want to copy a selective portion of the html content and paste that content in an excel 2007 file where it will be pasted as a normal text (not...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: 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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.