C ?

Discussion in 'Software' started by THE_INFERNO, Oct 9, 2004.

  1. THE_INFERNO

    THE_INFERNO Private E-2

    when i make the basic hello world program as soon as i run it, it closes how do i end that? and can any one plz tell me if there is a way to see your IP with C?

    thanks :) ;) :cool:
     
  2. NeoNemesis

    NeoNemesis Moutharrhea

    If you are running it you need to run it through the command prompt. Or you can always set it to sleep and then make the number -1 so it would be sleep -1 at the end. I'm not sure if thats how to do it in c but it is in c++. But I know for a fact taht if you run it from the command prompt it will work.
     
  3. QuickSilver

    QuickSilver Corporal

    Yea a lot depends on the environment its being run in. For instance if you write the program in something like Visual C++ and run it it automatically runs in a command window but once the program finishes that window automatically closes.
    Add a 'getch();' statement before your main function returns or ends and the program will wait till you hit a key if the above is the case.
     
  4. animatorStrike

    animatorStrike <a href="http://www.acrodata.com/fun/waaa.jpg">Rid

    You can put "cin.get();" before "return 0;" and that will keep the window open until you hit a key.
     
  5. QuickSilver

    QuickSilver Corporal

    hmmm gonna be picky now - but that command looks suspiciously like a C++ method call... sorry... Im bored.
     
  6. animatorStrike

    animatorStrike <a href="http://www.acrodata.com/fun/waaa.jpg">Rid

    It is C++. :p
     
  7. iamien

    iamien Cptn "Eh!"

    #include <stdio.h>


    system("Pause");

    or

    getch()

    and the answer to IP question

    Code:
    link in  winsock libs, forget the names
    include windows.h
    
         WSADATA WsaDat;
         if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)
               {
                printf("WSA Initialization failed.");
               }
    
          SOCKET Socket;
          Socket = socket(AF_INET, SOCK_STREAM, 0);
          if (Socket == INVALID_SOCKET)
               {
              printf("Socket creation failed.");
               }
    
    HOSTENT *HostInfo;
    HostInfo = gethostbyname("computer");
    if (HostInfo == NULL)
          {
          printf("Attempt to retreive computer information failed.");
          }
    
    SOCKADDR_IN SockAddr;
    HOSTENT *HostInfo;
    SockAddr.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)HostInfo->h_addr_list[0][0];
    SockAddr.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)HostInfo->h_addr_list[0][1];
    SockAddr.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)HostInfo->h_addr_list[0][2];
    SockAddr.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)HostInfo->h_addr_list[0][3];
    
    code for ip taken from
    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2241&lngWId=3
     
  8. THE_INFERNO

    THE_INFERNO Private E-2

    thanks every one
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds