how do i use xtern in my program to open nano please?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how do i use xtern in my program to open nano please?
Hi,
Can someone please tell me what iv done wrong with my string and how i use xtern to open nano from my c++ program please?, i need it to work from case 2, choice 1 (edit config) help much appreciated! Code below
Code:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
char string[30]; // set char size to 30 for input
ofstream outfile("games.db", ios::app);
myeditor="xterm -e /usr/bin/nano" // set path to nano
// Start Main Menu
char choice='\0';//NULL;
bool finished=false;
while (finished != true)
{
cout<<"MAIN MENU\n";
cout<<"1. AddGame\n";
cout<<"2. Options\n";
cout<<"3. RunGame\n";
cout<<"4. Exit\n";
cout << "Please enter your choice: ";
cin>>choice;
cout<<"\n\n";
// Start function for submenu
switch(choice)
{
case '1': cout << "1. Add Game To DB\n";
cout << "2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice == '1')
{
cout << "\n\nPlease enter full-path to game start file: ";
cin.get();
cin.getline (string, 30); // Input goes in$
if (outfile.is_open())
{
outfile<<string<<"\n";
outfile.close();
}
}
/* Just break if choice != 1 */
break;
case '2': cout<<"Options\n";
cout<<"1. Edit Game Config\n";
cout<<"2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice == '1');
{
cout << "Please enter full path to config file:";
cin.get()
cin.getline (string, 30); // input goes in
myeditor += string; exec(myeditor.c_str());
}
/* Just break if choice != 1 */
break;
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '3': cout<<"Run Game";
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '4': //Finished so set finished 'true' to break out of loop
finished=true;
cout<<"Exiting....\n";
break;
default: //If choice !=1/2/3 then do what it says here
break;
// end functions
}
choice='\0'; //NULL
}
return 1;
}
My problem is now i have created a string, i dont see how i can use it in my if statement from case 2, please help? code below :-
Code:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
char string[30]; // set char size to 30 for input
ofstream outfile("games.db", ios::app);
string my_editor; // create string my_editor
my_editor = "xterm -e /usr/bin/nano" // set path for nano
// Start Main Menu
char choice='\0';//NULL;
bool finished=false;
while (finished != true)
{
cout<<"MAIN MENU\n";
cout<<"1. AddGame\n";
cout<<"2. Options\n";
cout<<"3. RunGame\n";
cout<<"4. Exit\n";
cout << "Please enter your choice: ";
cin>>choice;
cout<<"\n\n";
// Start function for submenu
switch(choice)
{
case '1': cout << "1. Add Game To DB\n";
cout << "2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice == '1')
{
cout << "\n\nPlease enter full-path to game start file: ";
cin.get();
cin.getline (string, 30); // Input goes in$
if (outfile.is_open())
{
outfile<<string<<"\n";
outfile.close();
}
}
/* Just break if choice != 1 */
break;
case '2': cout<<"Options\n";
cout<<"1. Edit Game Config\n";
cout<<"2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice=='1')
{
cout << "Please enter full path to config file to edit"; // ask user for path to config file
cin.get()
cin.getline (string, 30); // input goes in
goto my_editor; // open up nano to edit config
}
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '3': cout<<"Run Game";
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '4': //Finished so set finished 'true' to break out of loop
finished=true;
cout<<"Exiting....\n";
break;
default: //If choice !=1/2/3 then do what it says here
break;
// end functions
}
choice='\0'; //NULL
}
return 1;
}
Ok, iv decided to use system() instead, but now when i try and compile i get an syntex error at line 57 : syntex error before '.' token ? i cant see whats wrong with that line. Please help code below.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char s1[30],s2[256]; // set char size to 30 and 256 for input
ofstream outfile("games.db", ios::app);
// Start Main Menu
char choice='\0';//NULL;
bool finished=false;
while (finished != true)
{
cout<<"MAIN MENU\n";
cout<<"1. AddGame\n";
cout<<"2. Options\n";
cout<<"3. RunGame\n";
cout<<"4. Exit\n";
cout << "Please enter your choice: ";
cin>>choice;
cout<<"\n\n";
// Start function for submenu
switch(choice)
{
case '1': cout << "1. Add Game To DB\n";
cout << "2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice == '1')
{
cout << "\n\nPlease enter full-path to game start file: ";
cin.get();
cin.getline (s1, 30); // Input goes in$
if (outfile.is_open())
{
outfile<<s1<<"\n";
outfile.close();
}
}
/* Just break if choice != 1 */
break;
case '2': cout<<"Options\n";
cout<<"1. Edit Game Config\n";
cout<<"2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice=='1')
{
cout << "Please enter full path to config file to edit: "; // ask user for path to config file
cin.get()
cin.getline (s2, 256); // input goes in
system("/usr/bin/pico"); // open up pico to edit config
}
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '3': cout<<"Run Game";
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '4': //Finished so set finished 'true' to break out of loop
finished=true;
cout<<"Exiting....\n";
break;
default: //If choice !=1/2/3 then do what it says here
break;
// end functions
}
choice='\0'; //NULL
}
return 1;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.