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

Reading from file into multiple structures

1
Hi All,


I am having problems reading from a file into an array of structures.
I have defined an array of 100 structures as shown below.

struct address_t

{

char name[name_size];

int comp_one, comp_two, comp_three, comp_four ;

} ;struct address_t address[100];


I can fscanf into one structure no problems but cant work out how to scan into more than one. Here is the fscanf function that I am currently using-

fscanf(InFile,"%d.%d.%d.%d %s",&ap->comp_one, &ap->comp_two, &ap->comp_three, &ap->comp_four,&ap->name);

ap is the pointer to the structure.

I want to do something like this -

fscanf(InFile,"%d.%d.%d.%d %s",&ap->[i]comp_one, &ap->[i]comp_two, &ap->[i]comp_three, &ap->[i]comp_four,&ap->[i]name);

and use a for loop with the counter (i) do that I can scan to the next structure out of the 100 possible.

Any Ideas would be greatly appreciated,


Thanks for your time,


Paul.
Oct 27 '06 #1
1 2492
Banfa
9,065 Expert Mod 8TB
I want to do something like this -

fscanf(InFile,"%d.%d.%d.%d %s",&ap->[i]comp_one, &ap->[i]comp_two, &ap->[i]comp_three, &ap->[i]comp_four,&ap->[i]name);

and use a for loop with the counter (i) do that I can scan to the next structure out of the 100 possible.
This is "want you want to do" and it would fix the problem. The only thing I can't work out is why you haven't done it?
Oct 27 '06 #2

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

Similar topics

3
by: Matt Laver | last post by:
Hi, I have a binary file that I'm currently reading byte by byte using code similiar to: string FileName = @"c:\myFile.dat"; FileStream fs = new FileStream(FileName, FileMode.Open,...
3
by: Usenet User | last post by:
I am trying to read (and then save) a binary file which has certain data structures in it. (The file is in propritetary format produced by a 3rd party MFC application.) I know that those data...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
3
by: Zeke Zinzul | last post by:
Hi Guys & Geeks, What's the most elegant way of dealing with binary data and structures? Say I have this (which I actually do, a woo-hoo): struct Struct_IconHeader { byte width; byte...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
1
by: tigerved | last post by:
Hi I am new to this so I dont exactly know the format in which to post the questions ....anyways here goes ...my file looks like this Year,Day,MOnth,latitude,longitude (commas included)...
9
by: Bill Woessner | last post by:
Suppose I have a structure, foo, which is a POD. I would like to read and write it to disk as follows: std::ofstream outs; foo bar; outs.write(reinterpret_cast<char*>(&bar), sizeof(foo));...
0
by: jigsmshah | last post by:
I have a windows service developed in C#.I am reading the connection string from an ini file and also i am reading 3 image file from the bin directory. now the new requirement is that there will be...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
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...
0
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,...

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.