LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-11-2005, 11:19 PM   #46
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15

ahh, hmm in the file system_errors its got :_

MAIN MENU
1. AddGame
2. Options
3. RunGame
4. Exit
Please enter your choice:


and that is all
 
Old 09-11-2005, 11:22 PM   #47
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
And you placed system_errors in the system() call in the code?
 
Old 09-11-2005, 11:28 PM   #48
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
Hi,

no sorry i dont know how :-( sorry for being a pain
 
Old 09-11-2005, 11:33 PM   #49
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Just concatenate " > system_errors" with the s3 before passing it to system().
 
Old 09-12-2005, 12:10 AM   #50
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
ok, im trying cin.getline(s3,>system_errors, 100); but that seems to be wrong? please excuse my ability to think at 6:10am in the morning.
 
Old 09-12-2005, 12:12 AM   #51
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
system(s3+" > system_errors");
 
Old 09-12-2005, 12:24 AM   #52
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
Ok, im getting the following compile errors my code is below also :-

gameserverpro14.cpp: In function `int main()':
gameserverpro14.cpp:82: error: invalid operands of types `char[256]' and `const
char[17]' to binary `operator+'
gameserverpro14.cpp:83: error: syntax error before `,' token


Code:
cout << "Please select game you wish to run: ";
cin.get();
system(s3+" > system_errors");
cin.getline(s3,, 100); //input goes in
 
Old 09-12-2005, 07:40 AM   #53
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
whoops, my bad. I thought it was a string type. You could do something nasty like:
system ( (string(s3)+" > system_errors").c_str() );
 
Old 09-12-2005, 10:04 AM   #54
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
ok ty, iv got it as below, because i cant have system above cin.getline as i get compile errors if i do.

Code:
cout << "Please select game you wish to run: ";
             cin.get();
             cin.getline(s3, 100);
             system ( (string(s3)+" > system_errors").c_str() );
 
Old 09-12-2005, 10:11 AM   #55
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
Hi,

ok iv ran my program where my bf2 gameserver is and this what happened when i try and run it through the program, :-

Run Game1. Battlefield 2
Please select game you wish to run: 1
sh: line 1: 1: command not found

thankyou
 
Old 09-12-2005, 10:12 AM   #56
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
oops forgot the code :-

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
int main()
{
 int i=0;
 char s1[30],s2[40],s3[90],s4[100];      // set char size for input
 ofstream outfile("games.db", ios::app);
 string whole,p1,p2;
 ifstream infile;
 
// 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$
                          outfile << s1 << ":";  // add : after eachpath
			   cout << "\n\nPlease enter game name: ";
                          cin.getline (s2, 40); 
                          outfile << s2 << "\n";
                if (outfile.is_open())
                          {
                           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 (s3, 256);        // input goes in
              string cmd = string("pico ") + string(s2);
              system(cmd.data());      // 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";
             i=0;
             infile.open ("games.db", ios::in);  
             while(getline(infile,whole)){
                 i++;
                 p2=whole.substr(whole.find(':')+1,whole.length());  
                 cout << i << ". " << p2 << endl;
             }                  
             cout << "Please select game you wish to run: ";
             cin.get();
             cin.getline(s3, 100);
             system ( (string(s3)+" > system_errors").c_str() );
             
             // 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-12-2005, 12:24 PM   #57
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Yeah, you need to put the command in there, not the number. Get the command from games.db.
 
Old 09-12-2005, 01:25 PM   #58
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
ok so i need to search my file for entry #, and find the command to run or load it all in memory and use std::map or something.

The problem is i have no idea how todo either of them, as i aint even done anything with std::map yet.

thankyou

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
int main()
{
 int i=0;
 char s1[30],s2[40],s3[90],s4[100];      // set char size for input
 ofstream outfile("games.db", ios::app);
 string whole,p1,p2;
 ifstream infile;
 
// 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$
                          outfile << s1 << ":";  // add : after eachpath
			   cout << "\n\nPlease enter game name: ";
                          cin.getline (s2, 40); 
                          outfile << s2 << "\n";
                if (outfile.is_open())
                          {
                           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 (s3, 256);        // input goes in
              string cmd = string("pico ") + string(s2);
              system(cmd.data());      // 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";
             i=0;
             infile.open ("games.db", ios::in);  
             while(getline(infile,whole)){
                 i++;
                 p2=whole.substr(whole.find(':')+1,whole.length());  
                 cout << i << ". " << p2 << endl;
             }                  
             cout << "Please select game you wish to run: ";
             cin.get();
             cin.getline(s3, 100);
             system ( (string(s3)+" > system_errors").c_str() );
             
             // 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-12-2005, 03:12 PM   #59
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I would not use std::map. Instead, just read through the file and count your position.
 
Old 09-12-2005, 03:28 PM   #60
twirl
Member
 
Registered: Aug 2005
Posts: 168

Original Poster
Rep: Reputation: 15
Hi,

i tried changing the code to what is below but that dont seem to fix it, that does, is it because iv got it the wrong way round and it should be i-- and not i++ ?

:-

un Game1. Battlefield 2
Please select game you wish to run:
1
sh: line 1: 1: command not found

My code :-

Code:
case '3': cout<<"Run Game";
             i=0;
             infile.open ("games.db", ios::in);  
             while(getline(infile,whole)){
                 i++;
                 p2=whole.substr(whole.find(':')+1,whole.length());  
                 cout << i << ". " << p2 << endl;
             }                  
             cout << "Please select game you wish to run: " << endl;
             cin.get();
             cin.getline(s3, 100);
             i=0;
             infile.open ("games.db", ios::in);  
             while(getline(infile,whole)){
                 i++;
                 p1=whole.substr(whole.find(':')-1,whole.length());  
                 cout << i << ". " << p1 << endl;
             }              
             system ( (string(s3)+" > system_errors").c_str() );
 
  


Reply



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
Why aint it reading file correctly? twirl Programming 11 09-13-2005 03:30 PM
How do i open a file user specifys? twirl Programming 1 09-06-2005 10:22 PM
firefox dos not open when run under user (opens only in root) saso Mandriva 8 06-15-2005 10:07 AM
trying to download PDF file -- it always OPENS 1kyle Linux - Software 1 07-24-2004 05:34 AM
what opens a .bz file? Chooco Linux - Newbie 15 06-18-2002 11:48 AM

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

All times are GMT -5. The time now is 01:16 PM.

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