Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-03-2004, 08:41 AM   #1 (permalink)
keystoneman
Registered User
 
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
keystoneman is on a distinguished road
Send a message via AIM to keystoneman
main menu

I have done some work while in college and it is all saved, what I want to do is create a main menu program that will probably be driven off a case statment but anywho I was wondering if there was anyway I could attatch external .cpp files to the main menu.


Example ...

* If the user enters 1 then 1.cpp is loaded (1.cpp being a program I have already created)

* If the user enters 2 then 2.cpp is loaded (2.cpp being a program I have already created)

... and so on for however many programs I have saved, is this possible?
keystoneman is offline   Reply With Quote
Old 11-03-2004, 09:32 AM   #2 (permalink)
frrossk
Registered User
 
frrossk's Avatar
 
Join Date: Sep 2004
Posts: 6
frrossk is on a distinguished road
You mean you want to call other programs from inside your program? This can be done using the spawnxx functions.
frrossk is offline   Reply With Quote
Old 11-03-2004, 10:21 AM   #3 (permalink)
keystoneman
Registered User
 
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
keystoneman is on a distinguished road
Send a message via AIM to keystoneman
Yes I want to call other .cpp files from my mainmenu.cpp
keystoneman is offline   Reply With Quote
Old 11-04-2004, 06:59 AM   #4 (permalink)
keystoneman
Registered User
 
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
keystoneman is on a distinguished road
Send a message via AIM to keystoneman
?
keystoneman is offline   Reply With Quote
Old 11-04-2004, 07:31 AM   #5 (permalink)
frrossk
Registered User
 
frrossk's Avatar
 
Join Date: Sep 2004
Posts: 6
frrossk is on a distinguished road
To call other programs, or to open .cpp files? These are 2 different kind of things, since a .cpp file is a text file, not a program...

Last edited by frrossk; 11-04-2004 at 07:34 AM. Reason: bad spelling
frrossk is offline   Reply With Quote
Old 11-04-2004, 11:48 AM   #6 (permalink)
keystoneman
Registered User
 
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
keystoneman is on a distinguished road
Send a message via AIM to keystoneman
Ok maybe I can make myself a little more clear, what I have right now is 12 independent programs that are due at the end of the semester. Instead of turning in a folder to my teacher where he has to click on each different .cpp to open it I would like to create another .cpp file and it would act as the main menu from here he could select lab 1 through lab 12 once he enters which lab he wants to see that .cpp file is then loaded.

Example

Which lab would you like to view?

1. Lab 1
2. Lab 2
3. Lab 3
4. Lab 4

(if the user enter the number 4 then the case statment loads 4.cpp)

.... is this posible or is there another way to do all of this?
keystoneman is offline   Reply With Quote
Old 11-04-2004, 09:00 PM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
What means "loaded"? Do you just want to show the corresponding C++ code in console?
__________________
Valmont is offline   Reply With Quote
Old 11-05-2004, 05:15 AM   #8 (permalink)
keystoneman
Registered User
 
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
keystoneman is on a distinguished road
Send a message via AIM to keystoneman
Yeah I just want to have the code shown, loaded was just a figure of speach.
keystoneman is offline   Reply With Quote
Old 11-05-2004, 06:14 AM   #9 (permalink)
frrossk
Registered User
 
frrossk's Avatar
 
Join Date: Sep 2004
Posts: 6
frrossk is on a distinguished road
So, you have only to open the file (Lab x), then read the lines in that file and display them on the screen. A kind of:
Code:
fopen (Lab x);
while (!feof)
{
gets (file, string);
printf (string);
}
(just an idea)

Last edited by frrossk; 11-05-2004 at 06:15 AM. Reason: bad spelling
frrossk is offline   Reply With Quote
Old 11-06-2004, 02:27 AM   #10 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Code:
#include <iostream>
#include <string>
#include <fstream>

using std::cin;
using std::cout;
using std::string;
using std::ifstream;
using std::endl;
using std::getline;

int main(int argc, char *argv[])
{
   ifstream theFile;
   string theFileName;

   while(1)
   {
      cout<<"\t\t\tEnter the option:"<<endl;
      cout<<"\t\t\t1 = Lab 1.cpp"<<endl;
      cout<<"\t\t\t2 = Lab 2.cpp"<<endl;
      cout<<"\t\t\t3 = Lab 3.cpp"<<endl;
      cout<<"\t\t\t4 = Lab 4.cpp"<<endl;
      cout<<"\t\t\tCTRL+Z/D = quit."<<endl;

      getline(cin, theFileName);
      
      //User wants to quit?
      if( cin.eof() )
      {
         //User wants to quit. Get out of the while-loop.
         break;
      }
      
      //Assuming files are named like: Lab_1.cpp, Lab_2.cpp etcetera.
      theFileName.insert(0, "Lab_");
      theFileName += ".cpp";
      
      theFile.open( theFileName.c_str() );
      
      if( !theFile )
      {
         cout<<endl<<"ERROR!"<<endl;
         cout<<"Reason: could not open the file."<<endl;
         cout<<"Make sure your entry is valid."<<endl<<endl;
         theFile.close();
         theFile.clear();
      }
      
      if( theFile.is_open() )
      {
         cout<<"*** File starts below ***"<<endl<<endl;
         cout<<theFile.rdbuf();
         cout<<endl<<"*** File ended ***"<<endl<<endl;
         theFile.close();
      }
   }
   
   return 0;
}
__________________
Valmont is offline   Reply With Quote
Old 11-08-2004, 09:03 AM   #11 (permalink)
keystoneman
Registered User
 
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
keystoneman is on a distinguished road
Send a message via AIM to keystoneman
I'll mess around with it Val, thanx and I'll get back to you.
keystoneman is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
About the Right-click Context Menu plonkeroo Windows 3 09-29-2004 03:39 PM
Trying to get number of e-mails in a txt file to appear on my main page netpants PHP 4 08-19-2003 08:46 PM
main page CaN Opener Feedback 2 07-09-2003 04:30 PM
sources.list bdl Linux / BSD / OS X 2 05-08-2002 06:32 AM


All times are GMT -8. The time now is 12:56 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting