I was given an assignment to complete on database, i have created on but crashes after executing once, check it friends and please help, if you can modify or make it way, i'll be graceful.

Please find the coding in attachment section. thanks hope will get good response

WaltP commented: Why is this a poll? Please don't abuse the forum features like this. -3

Recommended Answers

You should have made a discussion thread not a poll.

Jump to Post

All 2 Replies

You should have made a discussion thread not a poll.

Line 48 of function_definition.cpp: When you allocate new storage for a C-style string (char*), you need to add the null-termination character. This means you need to allocate one more char than what is given by strlen(tName) . The same goes for line 663 (in function SaveToFile). As so:

Ptr->Name = new char[strlen(tName)+1];
strcpy(Ptr->Name, tName);
Ptr->Name[strlen(tName)] = '\0'; //set the null-termination character.

In function AddTo_End(), make sure that the Next pointer in NewNode is NULL (better be cautious when there are unknown bugs, even if setting NewNode->Next = NULL; might be redundant after all). The same pretty much holds for AddBefore_InBetween() (but I'm not sure what this function does, similarly, AddAfter_InBetween() is weird, it doesn't seem to actually add a node to the linked-list). Remember that you have no constructor for the Node struct, so it means that the value of Next in a newly created Node could be anything (a "garbage value"), so it needs to be set to NULL explicitly (at least somewhere).

Be const-correct. This usually helps in pointing out silent bugs (like unintentional changes in values). For instance, in function Node* SearchBy_Name(char* tName) , you should take the parameter as const char*. There is no bug there, but making everything const-correct usually helps overall, as a good coding practice.

Although it is probably not a problem, I would usually be a bit more confortable with if(strcmp(tName,i->Name) == 0) as opposed to if(!strcmp(tName,i->Name)) , it is also more idiomatic.

In function DeleteFrom_Start(), you do not check if Head is valid (not NULL), that could crash your application (when checking Head->Next) if you do one call too many. Just take advantage of the short-circuit && operator:

if((Head) && (Head->Next)) //the second check will only occur if the first one passed.

The same goes for DeleteFrom_End().

In function DeleteIn_Between(), you don't check whether the "i" Node is NULL. Have you considered that maybe the Current Node is not part of the list, and thus, the iteration would reach the end before finding it. That would cause a crash with your implementation.

In MenuOperation(), you do a heck of a lot of cin.ignore(); cin.ignore(0); cin.clear(); cin.sync();. Doing that will not hurt, but those calls are so redundant. Just one cin.ignore() in between inputs should do the trick just fine.

There might be other stuff, but I can't go through everything. This should give you a pretty good start at wielding out the bug.

I'm guessing you are not allowed to do so, but if you are, I would highly recommend you use the C++ standard libraries for what you are trying to do. C++ has a std::string class (in #include <string>) which is much nicer to use than C-style strings. And C++ also provides an implementation of a linked-list, called std::list (in #include <list>). This will make your life so much easier, if you are allowed to use those.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.