473,693 Members | 2,547 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LInked list Problems, Please help

I am trying to make a very basic text editor using a linked list,
fstream, sorting...

This is what i have so far
------------------------------------------------------------------------------------------------------------------------------------
The Linked.H --- Header file

#include <iostream>

using namespace std;

struct NodeType
{
char Data;
NodeType *Address;
};

//global variables
NodeType *list;
NodeType *before;
NodeType *here;
NodeType *after;
NodeType *NewNode;

//Prototypes
void AddNode(char item);
void Search(char Sv,bool & found);
void Insert(char item,char Sv);
void Delete(char item);
void Display();

void main()
{
bool found;
char Sv,item;
int input;
list = NULL;
before = NULL;
here = NULL;
after = NULL;
NewNode = NULL;

cout<<" Please Choose from the following menu\t";
cout<<"1. Add a Company\n";
cout<<"2. Delete a Company\n";
cout<<"3. Insert a Company\n";
cout<<"4. Display\n";
cout<<"5. Exit\n";
cin >>input;
switch (input)
{

case 1:
AddNode();
break;

case 2:
Delete();
break;

case 3:
Insert();
break;

case 4:
Display();
break;

default:
cout<<"Invalid option!"<<endl;
break;
}
void AddNode(char item)
{
NewNode= New NodeType; //Creates a new node
NewNode->Data=item; // Places item in the data field
NewNode->Address=list ; //Places the address of the next node into the
address field
list=NewNode; //updates the address of the list
}

void Display() // displays the data to the screen
{
here = list;
while(here != NULL)
{
cout<<here->Data<<" ";
here= here->Address;
}
}

void Search(char Sv, bool & found)
{
here = list;
found = false; before = list;
while((here != NULL) && ( !found))
{
if(Sv == here->Data)
{
found=true;
after=here->Address;
}

else
{
before=here;
here=here->Address;
}
}
void Delete(char item)
{
bool found;
Search(item, found);
if(found)
{
if(here==list)
{
list=after;
delete here;
}
else{ before->Address=afte r;
delete here;
}
else
cout<<"Cannot delete item"<<item<<"n ot in the list"<<endl;
}
}

void Insert(char item, char Sv)
{
bool found;
Search(Sv,found )
if(found)
{
NewNode = New NodeType; NewNode->Data=item;
here->Address=NewNod e;
NewNode->Address=afte r;
cout<<item<<"ad ded to the list after"<<Sv<<end l;
}
else
cout<<"Cannot Insert"<<Sv<<"n ot found";
}

-------------------------------------------------------------------------------------------------------------------------------
The readin/display file

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <cfloat>
//#include "Linked.h"

using namespace std;
string company;
string inputFileName;

int main ()
{
cout<<"This Program Is Designed To Modify A File(s)";
cout<<"\n Please Enter The Complete File Name\n";
cin>>inputFileN ame; //takes in the file name specified by the user
ifstream inStream;
ofstream outStream; //establishes connection and check for success
inStream.open(i nputFileName.da ta());
assert(inStream .good());
int count=0;

for(;;)
{
inStream>>compa ny;
if(inStream.eof ()) break;
cout<<"The File Contains"<<comp any<<"\n";
}
inStream.close( );
return 0;

}

---------------------------------------------------------------------------------------------------------------------------------

My main problem is i'm getting a message that says local definitions
are illegal
I'm not sure what it could be, i have searched a few forums/sites and
they all state you probably are missing a brace but when i look it
seems fine...

Any help would be greatly appriciated

Thnanks very much....

Ryl

Dec 5 '05 #1
6 2426
* Ry****@comcast. net:
I am trying to make a very basic text editor using a linked list,
fstream, sorting...

This is what i have so far
------------------------------------------------------------------------------------------------------------------------------------
The Linked.H --- Header file

#include <iostream>

using namespace std;
Don't put that in a header file.

struct NodeType
{
char Data;
NodeType *Address;
};
What is 'Address'? Use self-descriptive names.
//global variables
NodeType *list;
NodeType *before;
NodeType *here;
NodeType *after;
NodeType *NewNode;
Don't use global variables.

//Prototypes
void AddNode(char item);
void Search(char Sv,bool & found);
void Insert(char item,char Sv);
void Delete(char item);
void Display();

void main()
'main' must have result type 'int'.

Don't put a 'main' function in a header file.

{
bool found;
char Sv,item;
int input;
list = NULL;
before = NULL;
here = NULL;
after = NULL;
NewNode = NULL;

cout<<" Please Choose from the following menu\t";
cout<<"1. Add a Company\n";
cout<<"2. Delete a Company\n";
cout<<"3. Insert a Company\n";
cout<<"4. Display\n";
cout<<"5. Exit\n";
cin >>input;
switch (input)
{

case 1:
AddNode();
Your prototype specifies an argument, in this call there is none.

break;

case 2:
Delete();
break;

case 3:
Insert();
break;

case 4:
Display();
break;

default:
cout<<"Invalid option!"<<endl;
break;
}
You probably want to put that menu thing in a loop.
void AddNode(char item)
{
NewNode= New NodeType; //Creates a new node
NewNode->Data=item; // Places item in the data field
NewNode->Address=list ; //Places the address of the next node into the
address field
list=NewNode; //updates the address of the list
}

void Display() // displays the data to the screen
{
here = list;
while(here != NULL)
{
cout<<here->Data<<" ";
here= here->Address;
}
}

void Search(char Sv, bool & found)
{
here = list;
found = false; before = list;
while((here != NULL) && ( !found))
{
if(Sv == here->Data)
{
found=true;
after=here->Address;
}

else
{
before=here;
here=here->Address;
}
}
Aren't you missing something here?

void Delete(char item)
{
bool found;
Search(item, found);
if(found)
{
if(here==list)
{
list=after;
delete here;
}
else{ before->Address=afte r;
delete here;
Aren't you missing something here?

}
else
Aren't you missing something here?
cout<<"Cannot delete item"<<item<<"n ot in the list"<<endl;
}
}


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 5 '05 #2
I dislike when other's replay to an issue without addressing the
problem, but the following is just FYI...

Unless this example is for an educational institution that is forcing
you to learn the fundamentals of linked lists, or you are running on an
embedded environment where your binary size is an issue... I would
recommend that you use STL lists or other container classes in leu of
creating your own. STL is easy to use has may features and is fully
tested. Using STL allows you to pay more attention to your business
logic and less on the implimentation of your linked list.

- Will

Dec 5 '05 #3
* Will:
I dislike when other's replay to an issue without addressing the
problem, but the following is just FYI...
Please read up on quoting, Will.

And also on netiquette in general.

Since I was the only one answering I assume you're talking about my
posting; there's no truth in your allegation.

Unless this example is for an educational institution that is forcing
you to learn the fundamentals of linked lists,


That is a reasonable assumption.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 5 '05 #4
He was actually refering to himself.
I dislike ..., *but* the following ...
Regards,
Marc

Dec 5 '05 #5
<m_*********@ho tmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com
He was actually refering to himself.
I dislike ..., *but* the following ...
Regards,
Marc


You are probably right, but in that case it was a curious choice to reply to
Alf rather than to the OP.

--
John Carson
Dec 5 '05 #6
Ry****@comcast. net wrote:
I am trying to make a very basic text editor using a linked list,
fstream, sorting...

This is what i have so far
------------------------------------------------------------------------------------------------------------------------------------ The Linked.H --- Header file

#include <iostream>

using namespace std;

struct NodeType
{
char Data;
NodeType *Address;
};

//global variables
NodeType *list;
NodeType *before;
NodeType *here;
NodeType *after;
NodeType *NewNode;

//Prototypes
void AddNode(char item);
void Search(char Sv,bool & found);
void Insert(char item,char Sv);
void Delete(char item);
void Display();

void main()
{
bool found;
char Sv,item;
int input;
list = NULL;
before = NULL;
here = NULL;
after = NULL;
NewNode = NULL;

cout<<" Please Choose from the following menu\t";
cout<<"1. Add a Company\n";
cout<<"2. Delete a Company\n";
cout<<"3. Insert a Company\n";
cout<<"4. Display\n";
cout<<"5. Exit\n";
cin >>input;
switch (input)
{

case 1:
AddNode();
break;

case 2:
Delete();
break;

case 3:
Insert();
break;

case 4:
Display();
break;

default:
cout<<"Invalid option!"<<endl;
break;
}
void AddNode(char item)
{
NewNode= New NodeType; //Creates a new node
NewNode->Data=item; // Places item in the data field
NewNode->Address=list ; //Places the address of the next node into the
address field
list=NewNode; //updates the address of the list
}

void Display() // displays the data to the screen
{
here = list;
while(here != NULL)
{
cout<<here->Data<<" ";
here= here->Address;
}
}

void Search(char Sv, bool & found)
{
here = list;
found = false; before = list;
while((here != NULL) && ( !found))
{
if(Sv == here->Data)
{
found=true;
after=here->Address;
}

else
{
before=here;
here=here->Address;
}
}
void Delete(char item)
{
bool found;
Search(item, found);
if(found)
{
if(here==list)
{
list=after;
delete here;
}
else{ before->Address=afte r;
delete here;
}
else
cout<<"Cannot delete item"<<item<<"n ot in the list"<<endl;
}
}

void Insert(char item, char Sv)
{
bool found;
Search(Sv,found )
if(found)
{
NewNode = New NodeType; NewNode->Data=item;
here->Address=NewNod e;
NewNode->Address=afte r;
cout<<item<<"ad ded to the list after"<<Sv<<end l;
}
else
cout<<"Cannot Insert"<<Sv<<"n ot found";
}

------------------------------------------------------------------------------------------------------------------------------- The readin/display file

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <cfloat>
//#include "Linked.h"

using namespace std;
string company;
string inputFileName;

int main ()
{
cout<<"This Program Is Designed To Modify A File(s)";
cout<<"\n Please Enter The Complete File Name\n";
cin>>inputFileN ame; //takes in the file name specified by the user
ifstream inStream;
ofstream outStream; //establishes connection and check for success
inStream.open(i nputFileName.da ta());
assert(inStream .good());
int count=0;

for(;;)
{
inStream>>compa ny;
if(inStream.eof ()) break;
cout<<"The File Contains"<<comp any<<"\n";
}
inStream.close( );
return 0;

}

---------------------------------------------------------------------------------------------------------------------------------
My main problem is i'm getting a message that says local definitions
are illegal
I'm not sure what it could be, i have searched a few forums/sites and
they all state you probably are missing a brace but when i look it
seems fine...

Any help would be greatly appriciated

Thnanks very much....

Ryl


It seems you're defining functions inside the scope of function main().
For instance: AddNode is declared globally (which is correct off course),
but you try to define it inside main's scope. This is illegal.
Some compilers, though, offer the possibility to define local functions as
an extension to the standard.

Good luck.
Dec 7 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4889
by: cpptutor2000 | last post by:
I am using an STL list to store data packets in a network simulator. The data packets are really C structs, which have other C structs inside them. These structs contain unsigned char arrays of various sizes, and some unsigned int values. There are no pointers values stored in these structs. I have a function, from inside of which I have a loop as follows: Please note that dataPacketStore is the name of the struct being stored. ...
5
3196
by: Kalvin Schroder | last post by:
I am fairly new to Access, and am trying to put together an invoice form. The main form in called InvoiceDetailFm. Source is the table InvoiceDetail and has invoice number, saleman, and CustID as some of its fields. I have put together a combobox, named it CustID, and am trying to use DLookup() to bring the complete Customer Name etc onto the form using DLookup() function for the fields I need. The combobox will bring up the CustID in...
1
1177
by: paul cooke | last post by:
Hi All I hope somebody out ther will help me. I am very very new to Access and I wish to create a list box on a form that displays items from a table. I then want to be able to view the list by using some sort of filter (say show me all the Fords on the list). I have been struggling for days and getting nowhere. Any help would be appreciated. Thanks
5
1736
by: Simon Mansfield | last post by:
Im trying to read in a list of employee's from a file, in the format: 01:SJM:Programmer:481 (<- £4.81 an hr) 02:AMG:Python Scripter:512 : : etc. When assigning to the "new" pointer it brings up an assignment error on line 33 and 34 of Staff.c, now these are the two string fields.. But I dont see
0
1206
by: Bennett F. Dill | last post by:
Thanks for reading. I'm having problems with cookies from asp to asp.net and back! It seems like I can set a cookie in asp.net fine, and alter it at will, as soon as asp touches it, asp.net won't have anything to do with it. Can someone please help! The code below, going from aspx to aspx, works great the cookie as expected goes from qwerty to zxcvb and back. As soon as you hit the asp page, the cookie goes to asdfg and stays there...
1
1155
by: Gaurav | last post by:
when i use the requiredfieldvalidator control on my web form and run the application i get the following message: Unable to find script library '/aspnet_client/system_web/1_1_4322/webuivalidatio n.js'. Try placing this file manually, or reinstall by running 'aspnet_regis -c'. How do i do any one of the both? Could somebody please help me? Thanks in advance.
5
1423
by: Irfan Akram | last post by:
Hi People, I am tryint to use the facilities of System.Web.Mail in order to implement an email sending facility in my web-based application. I get this error. An error occurred: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---
1
4949
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: http://munich.schwarz-interactive.de/autocomplete.aspx
0
8616
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8552
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8971
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8816
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7647
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4567
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.