how to output from a .txt file

Aug 20, 2014 at 3:20pm
So I have a .txt file with, Name >> Username >> password >> adminstatus.

It is filled with various names. for e.g.

Bob bobby bob123 1
tim timmy tim123 1
rit ritty rit123 0
john johnny john123 0
mary maryy mary123 mary 1

1 will represent admin in the program and 0 will represent a normal user. I want to make part of the program do something like this. > If adminstatus = 1, discount rate =3%. The thing is I will be using UDF to do so and I am unsure of how I am going to read for each user. What I mean by this is. If tim logins, how do I read ONLY tims line's admin status.


Currently I have a Login UDF. for that UDF I return something I named Loginstatus. If the login status = 1 . It will run the current problem that I'm trying to solve which is displaying the user adminstatus's discount rate. So how am I suppose to display the line of the user that logged in.


here is the simplified explaination of my program.

The user will login ( the program will see if everything matches up[username/password] then return loginstatus =1 if the user login succesfully) Once the user logs in the program will bring up a menu which will have 2 options. 1. it will let the user check it's current discount rate. 2. quit.


Aug 20, 2014 at 3:30pm
Hi
You need to basically parse the string that is read from the text file.

after every newline ('\n'), do

char[]ch;
int admin_status;
sscanf("%s %d",ch,admin_status)

This should give you a basic idea of how to approach the problem.

Chandra
Aug 21, 2014 at 1:03am
Is there a simpler way of doing it? I know your method is fairly short but i want to use a more "beginner" method doing it. I dont mind if it takes longer.
Topic archived. No new replies allowed.