|
-
March 1st, 2005, 04:44 PM
#1
File i/o
I need some help with a bank program where I need to read from a text file which contains id number, password, name, and balance. The trouble I'm having is with verifying the id number and then getting the information for that number to print to the screen. Any assistance would be greatly appreciated.
-
March 1st, 2005, 04:58 PM
#2
Re: File i/o
Your question has information which is no good for people to provide any solution. From your question one doesn't know what kind of application is it ? Is it written in C, C++ , using MFC , any other libraries. Please explain what exactly is the "trouble" also .
-
March 1st, 2005, 05:10 PM
#3
Re: File i/o
Alright it is written in C++ and the trouble is I don't know how to compare the ID number entered by the user to the ones in the .txt file and then extract the remaining information that partains to that ID number in said file and output it to the screen. Hopefully this fleshes the problem out a bit more and again any help would be greatly appreciated.
Last edited by Frylock; March 1st, 2005 at 05:14 PM.
Reason: trying to clarify
-
March 1st, 2005, 05:16 PM
#4
Re: File i/o
Some parts to this application:
1. File I/O. What are you using ? And are you having trouble with this ?
2. Parsing the file ? Are you doing this and are you having trouble in this area ?
3. Interpreting. i.e. you are comparing the file data with something in your or processing it. Any problem in this area ?
-
March 1st, 2005, 05:17 PM
#5
Re: File i/o
you could use a database instead of a text file to store the data and then just query the db with the info the user supplied
Or
you could read the whole file into an array of strings (one line per string) and then loop through the array searching for the ID. You'll have to parse the string to break out all the data.
Read the data in from the user as strings that way you can easily compare the values in the txt file.
I think you'll be better off using the database approach. If this is just a homework assignment then use the second option.
Last edited by Zim327; March 1st, 2005 at 05:19 PM.
Reason: more info
Best Regards,
--Zim If you find this post useful, please rate it.
_________________________________
"Have you the brain worms?!?!?"
-
March 1st, 2005, 05:29 PM
#6
Re: File i/o
So far I've read the .txt file with inFile and then have read the information with while(!inFile.eof()). Now I am trying to compare the user's information with the file without declaring everything but I'm probably going about this wrong. There is mention of parsing and no I have not done this but we haven't gone over this in class to my knowledge so is there another way or am I just stupid. Thanks for any help
-
March 1st, 2005, 05:40 PM
#7
Re: File i/o
each row in the txt file will contain 1 persons data, and you have to separate it all using a delimiter like a comma (,) or a pipe (|)
each line also ends with a "\n" you can use this as the delimiter to separate users
like so:
ID, password, name, balance
so you read in 1 line and store it in a string (or an array of strings) and Parse it (i.e. break out the data using the delimiter.
find the first comma and everthing in front of it is the ID extract the sub string
find the next comma everything in between is the password
and so on until you get to the end of the string.
Now you have the data stored in separate strings, compare it to what the user entered
if it matches then do your thing
if not then get the next line and start all over again.
Last edited by Zim327; March 1st, 2005 at 05:42 PM.
Best Regards,
--Zim If you find this post useful, please rate it.
_________________________________
"Have you the brain worms?!?!?"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|