We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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.

3
Contributors
2
Replies
10 Minutes
Discussion Span
2 Years Ago
Last Updated
3
Views
bleedsgreen33
Newbie Poster
20 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

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
Achieved Level 70
Team Colleague
32,155 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0597 seconds using 2.7MB