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

Filling Array Of Structures From A File

I'm having a hard time discovering how to fill an array of structures from a file. This is what I'm trying to do.

I am going to open a file from the command line. In the file are a bunch of records some of them in the proper format and some not. Each of the records are on one line of the file, like this.

Sumpter, David: 12445: 100: 85: 70: 78: B+
Laporte, Leo: 23855: 88:88: 100: 76: B
.
.
.
...and so on

Any ideas how I can get this type of data into an array of structures dynamically?

I don't need to handle all the records in the file just the first 100 valid records.
Nov 26 '08 #1
2 2381
Ganon11
3,652 Expert 2GB
I assume your struct will look something like:

Expand|Select|Wrap|Line Numbers
  1. struct Student {
  2.    string lname, fname, letterGrade;
  3.    int idNum, grades[4];
  4. };
(making the assumption based on your sample data that you are talking about students)

Can you assume that all the entries in your data file are separated by a ':'? If so, you can

a) Get a line from the file
b) Look for the first ':', and use everything before it as the last, first name.
c) Look for the next ':', and use everything before that as the idNum
d) Look for the next ':', and use everything before it as a grade
e) Repeat (d) for each entry in grades
f) Finally, take the remainder of the string as letterGrade.
g) Repeat (a)-(f) 100 times

This approach assumes that, as you get data from the line, you destroy the line in the process (i.e. after step (b), a data line might look like " 12445: 100: 85: 70: 78: B+").

However, if you cannot make the assumption that all your data entries will be separated by a ':', your job becomes almost impossible, and you may want to consider invalidating certain lines before even trying to process them.
Nov 26 '08 #2
Thanks that's just the jump start I needed!!
Nov 26 '08 #3

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

Similar topics

8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
3
by: MSDousti | last post by:
Hello I want to write a C# (or VB.NET) program which reads the structure of a PE (odinary win32 executable) file. These files have a long header (512 bytes or so). The definition of the header...
4
by: ned | last post by:
I have been having a lot of problems with an array of structures embedded in another structure in C++ .NET and have boiled it down to this very simple example: Try the following steps, it will...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
3
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
29
by: foker | last post by:
I have this problem where I have 2 text files, one with student name, id#, # of courses and course #, the second file has course name and course number. I want to make a multidimensional array that...
10
by: padh.ayo | last post by:
Hi, I have a array structure called people It is properly initialized to 100 array structure elements. Now, I'm reading in from the command line a txt file, and I get them to open correctly. In...
2
by: Marco Biagioni | last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio utility,i can't read correctly data bytes from a .bmp file to insert them in a matrix to operate on. Using vb 6.0 the...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
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: 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...
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)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.