Join 131,571 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,103 people online right now. Registration is fast and FREE... Join Now!
Alrighty. I'm gonna be on here alot until I get the hang of everything again. Below is a good portion of what I have so far for my log in portion of the program. This section is supposed to pull a user name (or list there of) and related password from a simple .dat file, insert the information into it's own node, if there's multiple nodes link them together, then get a user name and password from the user and compare them.
I compile the program perfectly but when I go to run it it crashes instantly on it. I'm not allocating memory right somewhere, somehow.
} else cout<<"Unable to load Userdatabase.doc"<<endl; }
void CreateNode(User *NewUserNode) // Creates and inserts node into Linked Lists { User *Hold; NewUserNode->UserNext = NULL; NewUserNode->UserPrev = NULL;
if(UserHead == NULL) // If the list is empty { UserHead = NewUserNode; // creates a new node and assigns it to head } else // if list is NOT empty { UserHead = UserCurrent; //current node is now head node UserCurrent = NewUserNode; //head node takes the value of the new node
UserHead->UserPrev = UserCurrent; // assigns the pointer to the previous node to the 'current node' UserCurrent->UserNext = UserHead; // current node's next pointer is assigned to the newly created head node
if (UserCurrent->UserPrev == NULL) // if there is only 2 items in the list they are also linked together { UserHead->UserNext = UserCurrent; UserCurrent->UserPrev = UserHead; }
else // if there is more then two in the list { Hold = UserCurrent; while(UserCurrent->UserPrev != NULL) // cycles through list until the end is reached { UserCurrent = UserCurrent->UserPrev; }
UserHead->UserNext = UserCurrent; // assigns the end of the list node's previous pointer to the head pointer UserCurrent->UserPrev = UserHead; // links the head pointer to the end of the list UserCurrent = Hold; // reassigns the current Node
}
}
}
void SysLogon() { char TempUserName[30]; char TempUserPass[30]; int a;
system("cls");
UserCurrent=UserHead; // assigns the head node to current node.
cout<<"Welcome to Vextor Banking Solutions' Banking System V. 1.00 (Test) (c) 2004 Vextor Inc. TM B-diddy Industries Rio Rancho NM\n"; cout<<"Username:"; cin.get(TempUserName, 30); cin.ignore(80, '\n'); cout<<"\nEnter Password\nPassword: "<<endl; cin.get(TempUserPass, 30); cin.ignore(80, '\n');
for(a=1; a<=UserCurrent->UserNodeCount; a++) //creates a loop based off number of nodes { if(strcmp(UserCurrent->UserName, TempUserName) == 0) // compares current node's username info to user entered info {
if(strcmp(UserCurrent->UserPass, TempUserPass) == 0) // compares passwords { cout<<"Welcome to Vextor Banking\n"<<endl; MainMenu(); } else { cout<<"System Login Failed: Invalid Password\n"<<endl; SysLogon(); } } else { UserCurrent=UserCurrent->UserPrev; // cycles to next node to verify information again } } cout<<"No such User found\n";
}
Oh, and any suggestions on making the program more efficient would be greatly appreciated as well.
Vextor, my apologies, I'm not currently near a compiler, so cannot do this myself.
Can you insert pauses (wait for char, any sort of user input) before each line of executable code, so see which ones execute before the crash (and output each loop iteration as well)?
Yeah for sure. Currently i'm at work so I'll have to wait until this evening but i'll do that and check it out myself. If I can't figure it out then i'll post what happens Thanks though. Until I can find a company that will allow me to download and install a compiler im stuck doing in my off time
This post has been edited by Vextor: 17 Nov, 2005 - 08:25 AM
From the code you've showen us: UserHead is undeclared/undefined UserCurrent is undeclared/undefined
CODE
UserHead = UserCurrent; //Not sure whta UserCurrent is, but why make it the head? UserCurrent = NewUserNode; //Did you mean for UserCurrent to be Tail? Point to the last node in the list?
UserHead->UserPrev = UserCurrent; //There is nothing before the head, head comes first therefore Head->Previous = NULL UserCurrent->UserNext = UserHead; //This would make the UserCurrent point to the head
after that i really kind of lose track of what you are trying to do.
Not too long ago i created a LinkedList class, it was pretty good, for storying data, maybe you wanna give it a try?
I think its pretty easy to use, and very convinient. I dont have any comments on it, so if you need clarification on something just IM me or post here
My AIM sn is StupidTerorrists
Attached File(s) linkedlist.h ( 1.97k )
Number of downloads: 19
UserHead and UserCurrent are pointers to the User Class. I just didn't post that part.
Basically i'm just adding the node to the head of the list and linking each node to the one infront of it and the one in back.
After looking at your class I have noticed a few things.
- I don't believe i'm using classes as efficiently or correctly as I can. - I need to read up on Templates - and I will likely NOT use yours
The reason is because I'm doing this project to learn. The best way I learn is by doing. I'll use yours as a reference (and I thank you profoundly) but I need to do this myself.
But after comparing the two (yours and mine) the only difference I see is that you add the nodes to the end whereas I'm attempting to add them to the head.
You are trying to add the nodes to the head? The head can only point to 1 node, unless the head class has more than one pointers to nodes.
But in a generic linked list, Head is usually the first element in the linked list, the tail is the last, and you have a current which is used to itirate through the list. Everything else is in order from first added to last added.
If i was you in the function CreateNode what i would do is check if the head is empty, if so asign the head to point to NewUserNode, else asign the last node's next pointer to the NewUserNode. Also set NewUserNode previous pointer to point to the Node before it, or the tail at the time. Then set the tail to point to NewuserNode.
I like how you have a pointer in the Node class that points to the previous Node. That creates a linked list that can be itirated both ways, in my Linked List you can only go forward, if you wanna go back you have to start from begining and itirate to the one you need.
I see what you're saying. What i'm attempting to do is a doublly/circularly linked list - I suppose I should have mentioned that!
My HeadPtr would be the 'first' in the list
I'm reading on templates now - I'll just have to make sense of it.
With that I think I can clean up the program a bit and create a .h file to handle most of this. I just got done reading another tutorial on OOP and it gave me some good ideas.
In any case i'm going to check it out a bit more closer when I get home - which will be in about 2 hours I'll post what I found out/change.
Vextor, I'm sure you're coming along well, but I just wanted ti let you know that you do not need templates for a circular, doubly linked list...or any linked list, for that matter.
And congrats on going for that oen...a circular double linked list will teach you all you need to know about linked lists!
Well after spending a bit of time on it last night and inserting a few well placed pauses I finally got it to work! Woohoo! That also includes the verification.
As of now it loads the info, creates lists and compares the info on the lists successfully.
But I managed to get the pointers mixed up somewhere so it's not pointing to EVERY pointer. That is however something I believe I can handle. I'll post everything once I get done.
As for templates - I know I don't NEED them but i'm under the impression they tend to make things easier... right?
I've read two tutorials on them and I still don't understand. Can somone just give me a quick run down on thier implementation?
Thanks - I just got done looking through it. Unfortunately just reading it isn't enough I think. I'm still at a loss, I'll have to just sit down some time this weekend and play around with it. I'll definately use these resources though, thanks again!
one quesiton.
If i were to use mrafcho001's template class above would I be able to use that same code for say... a customer set of nodes with information like account numbers and personal info, and a User set of nodes with user info like Username and Password? Is that how it works?
oh and what do the ? and single : operators do? as in...
CODE
size = s > 0 && s < 1000 ? s : 10;
pulled right out of the resource you gave me.
Thanks again - you've been an great help.
This post has been edited by Vextor: 18 Nov, 2005 - 10:02 AM