1,105,288 Community Members

Arrays Structs and File i/o

Member Avatar
bleedsgreen33
Newbie Poster
20 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

My professor has thrown me a curve ball with this next assignment. The assignment is to make a Monthly Accounting Statement, the program is to you structs and arrays. I get how you can have an array of structs, arrays within a struct, etc...

I have the program mapped out accept for this one part. When I reading in the customer names from the customer.txt file, some of the names have a middle initial, and some dont:

631502 Legg T. 2839 Lionel Ave. +16.30
180003 Hofstra M. 225 Smith Str -6.00
000963 Malioneyh P. J. 4344 Nero Rd +366.92
517724 Morier G. E. 19 Cumberland Ave +60.40
432649 Hauser M. 2940 Toronto Rd 0.00
817387 Currie W. D. 281 Harvard Str +55.00
913478 Hoos R. Dadie 821 County Road -100.00
713422 Smelly Tau 7281 Tobe Cir 0.00

Up until now, all the assignments have had entries similar, with a first and last name only so I just had to read through the file and put things in the appropriate place.

I'm not exactly sure how to go about this. I know it would have to be some kind of check. Do I need to fix the text file and make sure that there are tabs instead of spaces, and then do a check for that? I'm not even sure if my professor would allow me to change the .txt he gives us.

Member Avatar
WaltP
Posting Sage w/ dash of thyme
9,363 posts since May 2006
Reputation Points: 2,905 [?]
Q&As Helped to Solve: 1,151 [?]
Skill Endorsements: 45 [?]
Team Colleague
 
0
 

Read the entire line.
Check the characters looking for a letter. That's the beginning of the name and the end of the account number.
Next check looking for a digit. That's the beginning of the address and the end of the name.
Etc...

Member Avatar
Ancient Dragon
Achieved Level 70
27,577 posts since Aug 2005
Reputation Points: 5,231 [?]
Q&As Helped to Solve: 3,028 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

The first word in each line appears to be the account number. Everything from the end of the first word up to the first numeric digit can be assumed to be a name. After the name, everything up to either +, -, or a digit is the address.

There's a couple ways to solve the above.
[1]Read the file one character at a line and add the charactrers to the appropriate field in the structure.
[2]Read the entire line at one time then use a pointer to parse the input line.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: