Thread: Why is this killing itself?

  1. #1
    Unregistered
    Guest

    Why is this killing itself?

    #include <iostream.h>
    #include <stdlib.h>

    char name[4];
    void main()
    {
    cout<<"Please enter your name:";
    cin.getline(name, 4, '/n');
    cout<<"Your name is"<<name;
    return 0;
    }

    I don't see a thing wrong with it. Today is my first day learning, so I sorry if I'm being a retard.

    It pops up in the DOS window and kills itself when I input my four-letter name Jeff. Any ideas?

  2. #2
    Registered User Octorok101's Avatar
    Join Date
    May 2002
    Posts
    22
    If you check the post on the window closing too fast you will see a pause command. plug that in before return(0). also you might want to change void main to int main

  3. #3
    Unregistered
    Guest
    Interestingly, when I cut and paste code from the cprogramming.com guide, it also kills itself upon pressing enter.

  4. #4
    Registered User Octorok101's Avatar
    Join Date
    May 2002
    Posts
    22
    THe pause command is in a post called " to quick to read"
    hope I helped

  5. #5
    Unregistered
    Guest
    That keeps it up at least, thanks.

    Is there anyway without the "Press any key..." message?

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    ok before return use



    cout<<" Press a key to continue......";
    getch();



    That will work.. After the message is displayed.. It will wait for a user input.. After a key is pressed.. It closes..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having issues with killing suid programs
    By Overworked_PhD in forum Linux Programming
    Replies: 3
    Last Post: 12-13-2007, 08:20 AM
  2. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  3. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  4. Killing a process.
    By Brian in forum Windows Programming
    Replies: 7
    Last Post: 01-19-2003, 02:36 PM
  5. Functions are killing me
    By mike in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 02:35 PM