LinuxQuestions.org
Visit Jeremy's Blog.
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 12-16-2003, 10:57 PM   #1
nub47
LQ Newbie
 
Registered: Aug 2003
Posts: 18

Rep: Reputation: 0
debug problem w/ c++ code


can't figure out what's wrong w/ this piece of code
Code:
/*	
	Filename: tw.cpp
	Progname: Telnet Wargames
	By: MarkSpr4wl
	Date: December 16, 2003
	Purpose: Links to good telnet wargames
		 and telnet shell accounts
		 that might be of interest to
		 the novice and expert computer
		 buff alike.
*/
#include <iostream>	// for i/o: cout, cin, endl,cin.get(), etc.
#include <cstdlib>	// system() function for telnet site calls

using std::cin;		// using cin for input
using std::cout;	// using cout for output
using std::endl;	// using endl to endlines of output

int main(int argc, char** argv)
{
	char option;
	const char* errorMsg = '!';	// invalid input error message

	void call( void );	// calls() function prototype
	
	cout<< endl << endl << endl		// visual interface
	    << "\t- Telnet - Servers -" << endl << '\a'
	    << "\t--------------------" << endl << endl
	    << "\t1. Freeshell" << endl
	    << "\tQ..Quit" << endl;

	do
	{
		cout<< "\a\n\tEnter choice_ ";	// option input and decision call() function
		cin>> option;
		call(option);
	}
	while (option != 'q' || option != 'Q' || option != 0);
	
	if (option != '1' || option != 'q' || option !='Q' || option != 0) // if unwanted char, errorMsg
	{	
		cout<< '\t' << errorMsg << '\a' << endl;
		cout<< "\tEnter choice_ ";
		cin>> option;
	}
	
	cin.get();	// pause screen before exit
	return 0;

		void call(char option)	// decision switch/case function (system calls for telnet)
		{
			switch (option)
			{
			case '1' : system("telnet freeshell.org");

			case 'q' :
			case 'Q' : system("exit");	// system call for program exit
			}
		}
}
 
Old 12-16-2003, 11:04 PM   #2
nub47
LQ Newbie
 
Registered: Aug 2003
Posts: 18

Original Poster
Rep: Reputation: 0
fixed it in 5 minutes

Code:
/*
    Filename: tw.cpp
    Progname: Telnet Wargames
    By: MarkSpr4wl
    Date: December 16, 2003
    Purpose: Links to good telnet wargames
         and telnet shell accounts
         that might be of interest to
         the novice and expert computer
         buff alike.
*/
#include <iostream> // for i/o: cout, cin, endl,cin.get(), etc.
#include <cstdlib>  // system() function for telnet site calls

using std::cin;     // using cin for input
using std::cout;    // using cout for output
using std::endl;    // using endl to endlines of output

int main(int argc, char** argv)
{
    char option;
    const char* errorMsg = "invalid";   // invalid input error message

    void call(char option);  // calls() function prototype

    cout<< endl << endl << endl     // visual interface
        << "\t- Telnet - Servers -" << endl << '\a'
        << "\t--------------------" << endl << endl
        << "\t1. Freeshell" << endl
        << "\tQ..Quit" << endl;

    do
    {
        cout<< "\a\n\tEnter choice_ ";  // option input and decision call() function
        cin>> option;
        call(option);
    }
    while (option != 'q' || option != 'Q' || option != 0);

    if (option != '1' || option != 'q' || option !='Q' || option != 0) // if unwanted char, errorMsg
    {
        cout<< '\t' << errorMsg << '\a' << endl;
        cout<< "\tEnter choice_ ";
        cin>> option;
    }

    cin.get();  // pause screen before exit
    return 0;
}

void call(char option)   // decision switch/case function (system calls for telnet)
{
    switch (option) {
            case '1' : system("telnet freeshell.org");
            case 'q' :
            case 'Q' : system("exit");  // system call for program exit
    }
}
 
Old 12-17-2003, 12:31 AM   #3
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Code:
/*
    Filename: tw.cpp
    Progname: Telnet Wargames
    By: MarkSpr4wl
    Date: December 16, 2003
    Purpose: Links to good telnet wargames
         and telnet shell accounts
         that might be of interest to
         the novice and expert computer
         buff alike.
*/
#include <iostream> // for i/o: cout, cin, endl,cin.get(), etc.
#include <cstdlib>  // system() function for telnet site calls

using std::cin;     // using cin for input
using std::cout;    // using cout for output
using std::endl;    // using endl to endlines of output


void call(char option);  // calls() function prototype
const char* errorMsg = "invalid";   // invalid input error message

int main(int argc, char** argv)
{
    char option;


    cout<< endl << endl << endl     // visual interface
        << "\t- Telnet - Servers -" << endl << '\a'
        << "\t--------------------" << endl << endl
        << "\t1. Freeshell" << endl
        << "\tQ..Quit" << endl;

    do
    {
        cout<< "\a\n\tEnter choice_ ";  // option input and decision call() function
        cin>> option;
        call(option);
    }
    while (option != 0); // Checking for q or Q is redundant, it has quit allready.
    //What is this zero check anyway?
    /* Not needed
    if (option != '1' || option != 0) // if unwanted char, errorMsg (same thing here).
    {
        cout<< '\t' << errorMsg << '\a' << endl;
        cout<< "\tEnter choice_ ";
        cin>> option;
    }

    // Hmm.. this sounds like you don't want to exit in the call function afterall?
    cin.get();  // pause screen before exit
     */
    return 0;
}

void call(char option)   // decision switch/case function (system calls for telnet)
{
    switch (option) {
            case '1' :
              system("telnet freeshell.org");
              break;
            case 'q' :
            case 'Q' :
              exit(0); // A proper way to exit. system("exit") spawns a new session that runs "exit",
                       // meaning that it quits immediatedly.
            default: // This Might be a better place for bad input
                cout<< '\t' << errorMsg << '\a' << endl;
    }
}
 
  


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
small syntax problem with C code (implemented in Code Composer Studio) illiniguy3043 Programming 6 01-07-2008 02:14 AM
problem to debug in threads Ralf Becker Programming 5 09-01-2004 01:08 PM
How to debug Linux FAT filesystem code? ashishkumbhare Programming 2 04-14-2004 02:16 PM
how debug email problem? johnkantor12 Linux - Networking 7 11-23-2003 02:55 PM
C debug problem miasmak Programming 4 11-12-2001 01:33 PM

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

All times are GMT -5. The time now is 06:36 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