Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my problem is how to add go to function in this text editor and write in text editor?
and keyword and replace are also not working and show some errors?
C++
#include<iostream>
#include<conio.h>
#include <fstream>

using namespace std;
void updatetext();
void addtext();
void search();
void deletefile();
void display();
void update();
void replace();
int main()
{
	char admin;
	char user;
	int pass;
	int realpass=123;
	cout<<"***Press a for ADMIN or u for USER***"<<endl;
	cin>> admin;
	if(admin=='a'){
	cout<<"Please enter password :)"<<endl;
	cin>> pass;
		if(realpass==pass){	
			cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl;
	}
	
	else
	{
	cout<<"enter correct password please :( "<<endl;
	}
	}
	else if(user=='u'){
		cout<<"welcome to the function"<<endl;
		
	}
	char letter;
	cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl;
	
		cout<<"press 1 for WRITE "<<endl;
		cout<<"press 2 for UPDATE"<<endl;
		cout<<"press 3 for DELETE "<<endl;
		cout<<"press 4 for DISPLAY"<<endl;
		letter=getche();
		cout<<endl;
			
		switch (letter)
	{
		case '1':			
			{
				
		cout<<"press 1 to FIND "<<endl;
		cout<<"press 2 to FIND NEXT"<<endl;
		cout<<"press 3 to REPLACE"<<endl;
		cout<<"press 4 for GO TO"<<endl;
		cout<<"press 5 for TIME"<<endl;
		letter=getche();
		cout<<endl;

		
		switch (letter)
		{
		case'1':
			{
				search();
	         	cout<< "**FIND function**"<<endl; 
		     	break;  
			}
			case'2':
			{
				//keyword();
			cout<< "**FIND NEXT function**"<<endl; 
		     	break;
			}
		case'3':
		   {
		   	//replace();
		cout<< "**REPLACE function**"<<endl; 
		     	break;
      	}
		case'4':
		{
			cout<< "**GO TO function**"<<endl; 
		     	break;
	   }
	   case'5':
		{
			cout<< "**TIME function**"<<endl; 
		     	break;
	   }
	   
    }
    letter=getche();
    break;
	}
	 case'2':
	 	{
	
	 	cout<< "***You are in 'UPDATE' function***"<<endl;
	 	updatetext();
	 	break;
	 }
	 case'3':
	 	{	 	
	 		cout<< "***You are in 'DELETE' function***"<<endl;
	 		deletefile();
	 		break;
		 }
		 case'4':
	 	{
		 
	 		cout<<" ***You are in 'DISPLAY' function***"<<endl;
	 		display();
	 		break;
		 }
}
system("pause");
{
    system("COLOR FC");
    printf("Welcome to the color changing application!\n");
    printf("Press any key to change the background color!\n");
    getch();
    system("COLOR 7C");
    printf("Now the background color is white and Text Color is light Red\n");
    printf("Press any key to exit...");
    getch();
}
return 0;
}

void addtext(){
	ofstream o;
string text,fname;
cout<<"enter file name :"<<endl;
cin>>fname;
  o.open("fname");
  cout<<"Enter Text For"<<endl;
  cin>>text;
  o<<text;
  o.close();
}
void updatetext(){
	ofstream o;
string newtext;
  o.open("texteditor");
  cout<<"file text editor:"<<endl;
  cout<<"enter new text for"<<endl;
  cin>>newtext;
  o<<newtext;
  o.close();
}
void search(){
	string line;
	string search;
	ifstream myfile("texteditor");
	if(myfile.is_open())
	{
		while(getline(myfile,line))
		{			
			cout<<"enter string you want to search"<<endl;
			cin>>search;
		if(line==search){
			cout<<"line found";
		}
		cout<<line<<endl;
		cout<<"enter search for text"<<endl;
		cin>>search;
	}
	myfile.close();
}
	else cout<<"unable to open file"<<endl;
	
}
void deletefile(){
	if( remove( "texteditor" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );  
}

/* void keyword(ifstream &FileSearch)
{
	string letters;
	int position=-1;
	string line;
	ifstream readSearch;
	cout<<"enter search word";
	cin>>letter;
	"\n";
	FileSearch.open("texteditor");
	if(FileSearch.is_open())
	{
		while(getline(FileSearch,line))
		{
			FileSearch>>line;
			cout<<line<<endl;
			 
			position=line.find(letter,position+1);
			if(position==string);
			if(FileSearch.eof())
			break;
			cout<<line<<endl;
		}
	}
	cout<<"cant find"<<letters<<endl;
}
*/
void display(){
	ofstream o;
string newtext;
  o.open("texteditor");
  cout<<"File Text Editor:"<<endl;
  cin>>newtext;
  o<<newtext;
    o.close();
}

C++
include<iostream>
#include<conio.h>
#include <fstream>

using namespace std;
void updatetext();
void addtext();
void search();
void deletefile();
void display();
void update();
void replace();
int main()
{
	char admin;
	char user;
	int pass;
	int realpass=123;
	cout<<"***Press a for ADMIN or u for USER***"<<endl;
	cin>> admin;
	if(admin=='a'){
	cout<<"Please enter password :)"<<endl;
	cin>> pass;
		if(realpass==pass){	
			cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl;
	}
	
	else
	{
	cout<<"enter correct password please :( "<<endl;
	}
	}
	else if(user=='u'){
		cout<<"welcome to the function"<<endl;
		
	}
	char letter;
	cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl;
	
		cout<<"press 1 for WRITE "<<endl;
		cout<<"press 2 for UPDATE"<<endl;
		cout<<"press 3 for DELETE "<<endl;
		cout<<"press 4 for DISPLAY"<<endl;
		letter=getche();
		cout<<endl;
			
		switch (letter)
	{
		case '1':			
			{
				
		cout<<"press 1 to FIND "<<endl;
		cout<<"press 2 to FIND NEXT"<<endl;
		cout<<"press 3 to REPLACE"<<endl;
		cout<<"press 4 for GO TO"<<endl;
		cout<<"press 5 for TIME"<<endl;
		letter=getche();
		cout<<endl;
		
		switch (letter)
		{
		case'1':
			{
				search();
	         	cout<< "**FIND function**"<<endl; 
		     	break;  
			}
			case'2':
			{
				//keyword();
			cout<< "**FIND NEXT function**"<<endl; 
		     	break;
			}
		case'3':
		   {
		   	//replace();
		cout<< "**REPLACE function**"<<endl; 
		     	break;
      	}
		case'4':
		{
			cout<< "**GO TO function**"<<endl; 
		     	break;
	   }
	   case'5':
		{
			cout<< "**TIME function**"<<endl; 
		     	break;
	   }
	   
    }
    letter=getche();
    break;
	}
	 case'2':
	 	{
	
	 	cout<< "***You are in 'UPDATE' function***"<<endl;
	 	updatetext();
	 	break;
	 }
	 case'3':
	 	{	 	
	 		cout<< "***You are in 'DELETE' function***"<<endl;
	 		deletefile();
	 		break;
		 }
		 case'4':
	 	{
		 
	 		cout<<" ***You are in 'DISPLAY' function***"<<endl;
	 		display();
	 		break;
		 }
}
system("pause");
{
    system("COLOR FC");
    printf("Welcome to the color changing application!\n");
    printf("Press any key to change the background color!\n");
    getch();
    system("COLOR 7C");
    printf("Now the background color is white and Text Color is light Red\n");
    printf("Press any key to exit...");
    getch();
}
return 0;
}

void addtext(){
	ofstream o;
string text,fname;
cout<<"enter file name :"<<endl;
cin>>fname;
  o.open("fname");
  cout<<"Enter Text For"<<endl;
  cin>>text;
  o<<text;
  o.close();
}
void updatetext(){
	ofstream o;
string newtext;
  o.open("texteditor");
  cout<<"file text editor:"<<endl;
  cout<<"enter new text for"<<endl;
  cin>>newtext;
  o<<newtext;
  o.close();
}
void search(){
	string line;
	string search;
	ifstream myfile("texteditor");
	if(myfile.is_open())
	{
		while(getline(myfile,line))
		{			
			cout<<"enter string you want to search"<<endl;
			cin>>search;
		if(line==search){
			cout<<"line found";
		}
		cout<<line<<endl;
		cout<<"enter search for text"<<endl;
		cin>>search;
	}
	myfile.close();
}
	else cout<<"unable to open file"<<endl;
	
}
void deletefile(){
	if( remove( "texteditor" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );  
}

/* void keyword(ifstream &FileSearch)
{
	string letters;
	int position=-1;
	string line;
	ifstream readSearch;
	cout<<"enter search word";
	cin>>letter;
	"\n";
	FileSearch.open("texteditor");
	if(FileSearch.is_open())
	{
		while(getline(FileSearch,line))
		{
			FileSearch>>line;
			cout<<line<<endl;
			 
			position=line.find(letter,position+1);
			if(position==string);
			if(FileSearch.eof())
			break;
			cout<<line<<endl;
		}
	}
	cout<<"cant find"<<letters<<endl;
}
*/
void display(){
	ofstream o;
string newtext;
  o.open("texteditor");
  cout<<"File Text Editor:"<<endl;
  cin>>newtext;
  o<<newtext;
    o.close();
}


What I have tried:

I tried that one...

C++
#include<iostream>
#include<conio.h>
#include <fstream>

using namespace std;
void updatetext();
void addtext();
void search();
void deletefile();
void display();
void update();
void replace();
int main()
{
	char admin;
	char user;
	int pass;
	int realpass=123;
	cout<<"***Press a for ADMIN or u for USER***"<<endl;
	cin>> admin;
	if(admin=='a'){
	cout<<"Please enter password :)"<<endl;
	cin>> pass;
		if(realpass==pass){	
			cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl;
	}
	
	else
	{
	cout<<"enter correct password please :( "<<endl;
	}
	}
	else if(user=='u'){
		cout<<"welcome to the function"<<endl;		
	}
	char letter;
	cout<< "**** WELCOME TO THE TEXT EDITOR MENU ****"<<endl;
	
		cout<<"press 1 for WRITE "<<endl;
		cout<<"press 2 for UPDATE"<<endl;
		cout<<"press 3 for DELETE "<<endl;
		cout<<"press 4 for DISPLAY"<<endl;
		letter=getche();
		cout<<endl;
			
		switch (letter)
	{
		case '1':			
			{
				
		cout<<"press 1 to FIND "<<endl;
		cout<<"press 2 to FIND NEXT"<<endl;
		cout<<"press 3 to REPLACE"<<endl;
		cout<<"press 4 for GO TO"<<endl;
		cout<<"press 5 for TIME"<<endl;
		letter=getche();
		cout<<endl;
		
		switch (letter)
		{
		case'1':
			{
				search();
	         	cout<< "**FIND function**"<<endl; 
		     	break;  
			}
			case'2':
			{
				//keyword();
			cout<< "**FIND NEXT function**"<<endl; 
		     	break;
			}
		case'3':
		   {
		   	//replace();
		cout<< "**REPLACE function**"<<endl; 
		     	break;
      	}
		case'4':
		{
			cout<< "**GO TO function**"<<endl; 
		     	break;
	   }
	   case'5':
		{
			cout<< "**TIME function**"<<endl; 
		     	break;
	   }	   
    }
    letter=getche();
    break;
	}
	 case'2':
	 	{
	
	 	cout<< "***You are in 'UPDATE' function***"<<endl;
	 	updatetext();
	 	break;
	 }
	 case'3':
	 	{	 	
	 		cout<< "***You are in 'DELETE' function***"<<endl;
	 		deletefile();
	 		break;
		 }
		 case'4':
	 	{
		 
	 		cout<<" ***You are in 'DISPLAY' function***"<<endl;
	 		display();
	 		break;
		 }
}
system("pause");
{
    system("COLOR FC");
    printf("Welcome to the color changing application!\n");
    printf("Press any key to change the background color!\n");
    getch();
    system("COLOR 7C");
    printf("Now the background color is white and Text Color is light Red\n");
    printf("Press any key to exit...");
    getch();
}
return 0;
}

void addtext(){
	ofstream o;
string text,fname;
cout<<"enter file name :"<<endl;
cin>>fname;
  o.open("fname");
  cout<<"Enter Text For"<<endl;
  cin>>text;
  o<<text;
  o.close();
}
void updatetext(){
	ofstream o;
string newtext;
  o.open("texteditor");
  cout<<"file text editor:"<<endl;
  cout<<"enter new text for"<<endl;
  cin>>newtext;
  o<<newtext;
  o.close();
}
void search(){
	string line;
	string search;
	ifstream myfile("texteditor");
	if(myfile.is_open())
	{
		while(getline(myfile,line))
		{			
			cout<<"enter string you want to search"<<endl;
			cin>>search;
		if(line==search){
			cout<<"line found";
		}
		cout<<line<<endl;
		cout<<"enter search for text"<<endl;
		cin>>search;
	}
	myfile.close();
}
	else cout<<"unable to open file"<<endl;
	
}
void deletefile(){
	if( remove( "texteditor" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );  
}

/* void keyword(ifstream &FileSearch)
{
	string letters;
	int position=-1;
	string line;
	ifstream readSearch;
	cout<<"enter search word";
	cin>>letter;
	"\n";
	FileSearch.open("texteditor");
	if(FileSearch.is_open())
	{
		while(getline(FileSearch,line))
		{
			FileSearch>>line;
			cout<<line<<endl;
			 
			position=line.find(letter,position+1);
			if(position==string);
			if(FileSearch.eof())
			break;
			cout<<line<<endl;
		}
	}
	cout<<"cant find"<<letters<<endl;
}
*/
void display(){
	ofstream o;
string newtext;
  o.open("texteditor");
  cout<<"File Text Editor:"<<endl;
  cin>>newtext;
  o<<newtext;
    o.close();
}
Posted
Updated 8-Jun-19 22:45pm
v2
Comments
Richard MacCutchan 9-Jun-19 4:09am    
There is no point in just dumping a load of code without any explanation of what your problem is or where it occurs. Please edit your question and add some proper detail.

1 solution

When you want to add a new function, you must add the function declaration above the main function and implement it afterwards. (that is the style of your code - and it isnt the best way, but it works)

I think that you are missing basic programming knowledge and so should search for some online tutorial or similar stuff. Maybe you watch some videos.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900