954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Arrays Structs and File i/o

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.

bleedsgreen33
Newbie Poster
19 posts since Feb 2011
Reputation Points: 10
Solved Threads: 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...

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: