Quick Question (I Promise!)

This is a discussion on Quick Question (I Promise!) within the C++ Programming forums, part of the General Programming Boards category; What type of variable does one use when it's an ip address? like Float, Double, Int, String, whatever. for a ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    18

    Wink Quick Question (I Promise!)

    What type of variable does one use when it's an ip address?

    like Float, Double, Int, String, whatever. for a 192.168.1.1 piece of info? Thanks in advance.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Up to you. An array of 4 unsigned chars perhaps?

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    18
    I really prefer not to use an array, if possible. What one should I use if I don't?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    An int should be ok if you are on systems where an int is at least 32-bits. String should be safe.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    18
    Quote Originally Posted by MacGyver View Post
    An int should be ok if you are on systems where an int is at least 32-bits. String should be safe.
    Thank you, kind sir!

    edit: I get the error

    Conversion from string "192.168.1.1" to type 'Integer' is not valid.

    I'll try using String instead of Integer!

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Well, if you're trying to do something silly like this:

    Code:
    int x = "192.168.1.1";
    That's rather silly and it's no wonder it fails. Just use a string unless you're doing actual net coding.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    18
    It is pretty silly what I am doing. Thanks for the reply. One last question, if you wouldn't mind?

    I was unable to find this anywhere:

    How do you start a program with c++? I found delete, I found textfile opening, and all that stuff, but nowhere how to make it open a .exe file. It is possible, I assume.

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    You want your program to open (execute) another program? What OS? ShellExecute perhaps... one of the spawn family of functions... numerous others (system if you're desperate). Check the FAQ.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    18
    Windows XP. Like, add options to a program so you can start other stuff. Like Ping.exe with parameters and all kinda other stuff from one base program. I know it's simple. I know it's stupid. But I'd really like to know how. =) So, "ShellExecute" should work? What's it's usage? ShellExecute ("C:\Windows\system32\ping.exe") ?

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    CreateProcess() or CreateProcessEx()... I can't remember. Those are the "proper" ways of doing it on Windows.

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    18
    Well, this is slowly becoming a not so quick question. Oops.

    This is my code:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
        string a;
        string b;
        string c;
        
        cout << "Please Enter The I.P. Address: ";
        cin >> a; "\n";
        cout << "Please Enter any Parameters you wish to include (example: -t -l): ";
        cin >> b; "\n";
        cout << "Please enter the byte number you wish to send (0-65500): ";
        cin >> c; "\n";
        ShellExecute ("C:\windows\system32\ping.exe");
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    It gives the error:
    19:18 C:\Dev-Cpp\asdasd.cpp [Warning] unknown escape sequence '\w'
    19:19 C:\Dev-Cpp\asdasd.cpp [Warning] unknown escape sequence '\s'
    19:19 C:\Dev-Cpp\asdasd.cpp [Warning] unknown escape sequence '\p
    C:\Dev-Cpp\asdasd.cpp In function `int main()':
    19 C:\Dev-Cpp\Project.cpp cannot convert `const char*' to `HWND__*' for argument `1' to `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)' '
    C:\Dev-Cpp\Makefile.win [Build Error] [Project.o] Error 1
    Help please?

  12. #12
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Don't type random crap. Use google + MSDN.

    http://msdn2.microsoft.com/en-us/library/bb762153.aspx

  13. #13
    Registered User
    Join Date
    Oct 2007
    Posts
    66
    (edit2:, macgyver beat me to it )

    http://msdn2.microsoft.com/en-us/library/bb762153.aspx

    If you just want the simple version though:

    Code:
    ShellExecute(NULL, "open", "C:\\windows\\telnet.exe", "-o 127.0.0.1", SW_SHOW);
    I think that opens a telnet connection on XP, I may be wrong though.

    However, if all you want to do is ping or something you can probably use system() calls for simplicity.

    Code:
    string myString = "ping 127.0.0.1";
    
    system(myString.c_str());  // I think you need to pass this as a cstr for system?
    I may be wrong none of this code is tested but I think that works.


    EDIT:

    Note your errors, you need to use \\ instead of \ due to escape characters. IE: \windows needs to be \\windows or else the computer thinks you want to use whatever "\w" is as a code.
    Last edited by tjpanda; 10-16-2007 at 07:50 PM.
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

  14. #14
    Registered User
    Join Date
    Oct 2007
    Posts
    18
    Quote Originally Posted by tjpanda View Post
    (edit2:, macgyver beat me to it )

    http://msdn2.microsoft.com/en-us/library/bb762153.aspx

    If you just want the simple version though:

    Code:
    ShellExecute(NULL, "open", "C:\\windows\\telnet.exe", "-o 127.0.0.1", SW_SHOW);
    I think that opens a telnet connection on XP, I may be wrong though.

    However, if all you want to do is ping or something you can probably use system() calls for simplicity.

    Code:
    string myString = "ping 127.0.0.1";
    
    system(myString.c_str());  // I think you need to pass this as a cstr for system?
    I may be wrong none of this code is tested but I think that works.


    EDIT:

    Note your errors, you need to use \\ instead of \ due to escape characters. IE: \windows needs to be \\windows or else the computer thinks you want to use whatever "\w" is as a code.
    Gotcha, thanks for the reply m8.

    To Macgyver: Someone earlier said ShellExecute, I usually like to fiddle with stuff myself till it works, so that's what i did.

  15. #15
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You can fiddle all you want, but if you're going to ask for help, then make your attempts serious. Otherwise, you're just begging for us to do your research for you.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

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