LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-09-2005, 02:16 PM   #1
twirl
Member
 
Registered: Aug 2005
Posts: 168

Rep: Reputation: 15
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;

}
 
Old 09-10-2005, 09:14 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,795

Rep: Reputation: 496Reputation: 496Reputation: 496Reputation: 496Reputation: 496
Quote:
myeditor="xterm -e /usr/bin/nano" // set path to nano
myeditor is undeclared, and your instruction is unterminated.
 
Old 09-10-2005, 10:20 AM   #3
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
Thankyou for your reply.

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;

}
 
Old 09-10-2005, 01:17 PM   #4
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
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;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
su then open program in X fails uopjohnson Slackware 15 10-06-2005 07:36 PM
open a program from anywhere superpico Linux - Newbie 3 02-01-2005 07:57 PM
open program in another desktop Balkman Linux - Newbie 1 03-08-2004 05:16 PM
looking for an open source program that can... Eugene Programming 6 11-13-2003 02:53 AM
how to execute a console program within nano? breadbin Linux - Software 2 06-21-2003 07:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration