Ping problem

This is a discussion on Ping problem within the C++ Programming forums, part of the General Programming Boards category; Im intergrating alot of stuff in my program and I wanna make a ping thing inside of it, so I ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    69

    Ping problem

    Im intergrating alot of stuff in my program and I wanna make a ping thing inside of it, so I was thinking of starting it out with

    Code:
    char IP;
    void inpute()
    {
    cin >> IP;
    SYSTEM("ping IP")
    }
    I don't know how I would get the IP char infront of the system ping command so it would ping it. Any ideas?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    An IP address is probably up to 3*4+3 characters long ( xxx.xxx.xxx.xxx ). So you need a string instead of a single char.

    PHP Code:
        string ip;
        
    string command;

        
    cin >> ip;

        
    command "ping " ip;

        
    systemcommand.c_str() ); 
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Thank you! You roxors!

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    I get errors when I compile


    PHP Code:
      {
                
    string commands;
                
    string ip;
                
    cprintf ">> 2 - Pings specified IP Address\n" );
                
    cprintf ">> IP: ");
                
    cin >> ip
                
    commands "ping " ip;
                
    systemcommands.c_str() );
                
    cprintf ">> \n" );
                
    inpute();
            } 
    Code:
    Compiling...
    main.cpp
    c:\documents and settings\blade-new\my documents\visual studio projects\admin\funcs.h(12) : error C2146: syntax error : missing ';' before identifier 'commands'
    c:\documents and settings\blade-new\my documents\visual studio projects\admin\funcs.h(12) : error C2501: 'string' : missing storage-class or type specifiers
    c:\documents and settings\blade-new\my documents\visual studio projects\admin\funcs.h(12) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.
    
    ADMIN.exe - 3 error(s), 0 warning(s)

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Lets see the full source code. I seems like you are missing the <string> header you need

  6. #6
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Here goes my nubish code

    PHP Code:
    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h> 
    using std::cout;
    using std::cin;
    char command;
    int ch;

    char ip;

    // Inpute Function. checks all input.
    void inpute()
                            { 
           
    cprintf ">> \n" );
           
    cprintf ">> "  );
           
    cin >> command;
           
    cprintf ">> \n" );
           
    cprintf ">> \n" );
            if (
    command == '0')
                            {
                
    cprintf ">> 1 - Formats specified hard drive\n" );
                
    cprintf ">> -- syntax = 1 [Drive Letter]\n" );
                
    cprintf ">> 2 - Pings specified IP Address\n" );
                
    cprintf ">> -- syntax = 2 [IP Address]\n" );
                
    cprintf ">> 3 - Exits Blade Command 0.1\n" );
                
    cprintf ">> -- syntax = 3\n" );
                
    cprintf ">> 4 - Starts Putty\n" );
                
    cprintf ">> -- syntax = 4\n" );
                
    cprintf ">> 5 - Clears Console\n" );
                
    cprintf ">> -- syntax = 5\n" );
                
    inpute();
            } else {
            if (
    command == '1')
                            {
                
    cprintf ">> 1 - Formats specified hard drive\n" );
                
    cprintf ">> Currently not availible\n" );
                
    inpute();
            } else {
            if (
    command == '2')
                            {
                
    cprintf ">> 2 - Ping specified IP Address\n" );
                
    cprintf ">> IP: ");
                
    cin >> ip
                
    cprintf ">> \n" );
                
    inpute();
            } else {
            if (
    command == '3')
                    {
                
    cprintf ">> 3 - Exits Blade Command 0.1\n" );
                
    system("PAUSE");
            } else {
            if (
    command == '4')
                    {
            
    cprintf ">> 4 - Starts Putty\n" );
            
    cprintf ">> Putty Started\n" );
            
    system ("C:/putty.exe");
            
    cprintf ">> Putty Ended\n" );
                
    inpute();
            } else {
            if (
    command == '5')
                    {
                  
    system ("cls");
                
    inpute();
            }
            }
            }
            }
            }
            }
    }

    // Login Function
    void login()
    {
    int pass;
        
    cprintf ">> \n" );
        
    cprintf ">> == Authorization Required! ==\n" );
        
    cprintf ">> Enter numerical pass: " );
        
    cin >> pass;
        
    cprintf ">> \n" );
        if (
    pass == 123)
        {
            
    cprintf ">> Granted!\n" );
            
    cprintf ">> Please Enter a command, or type '0' for a list of commands!\n" );
            
    inpute();
        } else {
                
    cprintf ">> == Invalid Password! ==\a\n" );
                
    cprintf ">> \n" );
                
    login();
        }

    Thats before I added all the stuff

    Now After
    PHP Code:
    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h> 
    using std::cout;
    using std::cin;
    char command;
    int ch;

    char ip;

    // Inpute Function. checks all input.
    void inpute()
                            { 
           
    cprintf ">> \n" );
           
    cprintf ">> "  );
           
    cin >> command;
           
    cprintf ">> \n" );
           
    cprintf ">> \n" );
            if (
    command == '0')
                            {
                
    cprintf ">> 1 - Formats specified hard drive\n" );
                
    cprintf ">> -- syntax = 1 [Drive Letter]\n" );
                
    cprintf ">> 2 - Pings specified IP Address\n" );
                
    cprintf ">> -- syntax = 2 [IP Address]\n" );
                
    cprintf ">> 3 - Exits Blade Command 0.1\n" );
                
    cprintf ">> -- syntax = 3\n" );
                
    cprintf ">> 4 - Starts Putty\n" );
                
    cprintf ">> -- syntax = 4\n" );
                
    cprintf ">> 5 - Clears Console\n" );
                
    cprintf ">> -- syntax = 5\n" );
                
    inpute();
            } else {
            if (
    command == '1')
                            {
                
    cprintf ">> 1 - Formats specified hard drive\n" );
                
    cprintf ">> Currently not availible\n" );
                
    inpute();
            } else {
            if (
    command == '2')
                            {
                
    string commands;
                
    string ip;
                
    cprintf ">> 2 - Pings specified IP Address\n" );
                
    cprintf ">> IP: ");
                
    cin >> ip;
                
    commands "ping " ip;
                
    systemcommands.c_str() );
                
    cprintf ">> \n" );
                
    inpute();
            } else {
            if (
    command == '3')
                    {
                
    cprintf ">> 3 - Exits Blade Command 0.1\n" );
                
    system("PAUSE");
            } else {
            if (
    command == '4')
                    {
            
    cprintf ">> 4 - Starts Putty\n" );
            
    cprintf ">> Putty Started\n" );
            
    system ("C:/putty.exe");
            
    cprintf ">> Putty Ended\n" );
                
    inpute();
            } else {
            if (
    command == '5')
                    {
                  
    system ("cls");
                
    inpute();
            }
            }
            }
            }
            }
            }
    }

    // Login Function
    void login()
    {
    int pass;
        
    cprintf ">> \n" );
        
    cprintf ">> == Authorization Required! ==\n" );
        
    cprintf ">> Enter numerical pass: " );
        
    cin >> pass;
        
    cprintf ">> \n" );
        if (
    pass == 123)
        {
            
    cprintf ">> Granted!\n" );
            
    cprintf ">> Please Enter a command, or type '0' for a list of commands!\n" );
            
    inpute();
        } else {
                
    cprintf ">> == Invalid Password! ==\a\n" );
                
    cprintf ">> \n" );
                
    login();
        }

    Last edited by bladerunner627; 02-01-2005 at 03:58 PM.

  7. #7
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    yes, you are missing the <string> header

    before you can use strings you have to #include <string>
    Keyboard Not Found! Press any key to continue. . .

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Include the <string> header and put a using std::string; at the top and you should be in business.

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Ok thanks

  10. #10
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Ok everything works now! Thanks alot. Now since I can use that string header, It can solve me alot of problems. Earlier I couldnt figure out how to get multiple values into one char type :/. Im so nub.

  11. #11
    Registered User
    Join Date
    Feb 2005
    Posts
    4
    hi do you mind me asking what your program does?

  12. #12
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    .. Im at school now, but I can't make a resonable post without someone coming by, and smashing the keyboard

  13. #13
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Ok, well the program is suppose to make it easier for me to manage my website, and computer. Im also trying to impliment Winsock with it, so I can remotely upload files to my comp kinda like FTP. The ping is used for seeing if my server is up, so if for some reason im disconnected I can see if it went down, or its a software problem. format is self explanitory. Putty is a good shell program http://www.chiark.greenend.org.uk/~s.../download.html
    all I have to do is type 2, and putty starts up so I can shell my server/comp, ect. Just makes it easier for me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21