R
Rylios
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=after;
delete here;
}
else
cout<<"Cannot delete item"<<item<<"not 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=NewNode;
NewNode->Address=after;
cout<<item<<"added to the list after"<<Sv<<endl;
}
else
cout<<"Cannot Insert"<<Sv<<"not 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>>inputFileName; //takes in the file name specified by the user
ifstream inStream;
ofstream outStream; //establishes connection and check for success
inStream.open(inputFileName.data());
assert(inStream.good());
int count=0;
for(;
{
inStream>>company;
if(inStream.eof()) break;
cout<<"The File Contains"<<company<<"\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
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=after;
delete here;
}
else
cout<<"Cannot delete item"<<item<<"not 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=NewNode;
NewNode->Address=after;
cout<<item<<"added to the list after"<<Sv<<endl;
}
else
cout<<"Cannot Insert"<<Sv<<"not 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>>inputFileName; //takes in the file name specified by the user
ifstream inStream;
ofstream outStream; //establishes connection and check for success
inStream.open(inputFileName.data());
assert(inStream.good());
int count=0;
for(;
{
inStream>>company;
if(inStream.eof()) break;
cout<<"The File Contains"<<company<<"\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