Thread: Newbie Question :))

  1. #1
    Registered User
    Join Date
    May 2013
    Location
    Rishon Le Siyon, Hamerkaz, Israel, Israel
    Posts
    13

    Question Newbie Question :))

    Hey guys, It's me again

    I'm continuing to learn about the C language from my book and I got to the Pointers chapter so far.

    Just sharing that info with you guys cus i like this forum

    the newbie question of today is:

    I'm using VS2010Express (CPP) and so far when i compiled a code I used the getchar(); code to stop the program from closing..

    Is there any other way I can set the compiler to just not exit the program as soon as it finish read it ? If so i'll be more than happy to know

    TY great day.
    Last edited by Or Ellenbogen; 06-26-2013 at 08:59 AM.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    if you are using the debugger, you can set a breakpoint at the return statement in main. otherwise stopping to wait for user input is what you have to do.

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    17
    could try getch();

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Why use the non-standard getch() if he is complaining about using the standard function getchar()?

    Jim

  5. #5
    Registered User
    Join Date
    Jun 2013
    Posts
    66
    In Visual Studio, go to your project properties dialog. Under Linker->System, make sure that SubSystem is set to Console and the output window will no longer close on you.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by sonjared View Post
    In Visual Studio, go to your project properties dialog. Under Linker->System, make sure that SubSystem is set to Console and the output window will no longer close on you.
    Visual Studio is not Turbo C!

    Use sonjared's advice, and you never need to use getch() or getchar() to stop the Visual Studio program window from closing. Perish the thought!

    Visual Studio holds that window open for you, but the output window has to be set to Console.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    I think i am misunderstanding the question and answers here. I was referring to running in the debugger. I just looked at one of my many VS console apps, linker subsystem is set to console, ran the program in the debugger. it exited and the window closed. what am i missing?

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I was replying to Or Ellenbogen's query.

    I didn't use the debugger in Visual Studio enough to remember that clearly. IIRC there was a checkbox in the options for it, but it's been a long time since I used VS.

    When I moved my programs over to VS (from Turbo C), I do remember having to hit the enter and then any other key, to exit the console window - twice because each Turbo C program had to have a getch() or getchar() at the end of it, and VS did not require it. It held the console window open, without that getchar() being needed.

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    In VS - when you run program with Ctrl+F5 - the window stays open after program finish.

    If you run it with F5 and do not want it to close window automatically - just add breakpoint on the return from main()
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User
    Join Date
    May 2013
    Location
    Rishon Le Siyon, Hamerkaz, Israel, Israel
    Posts
    13
    Quote Originally Posted by vart View Post
    In VS - when you run program with Ctrl+F5 - the window stays open after program finish.

    If you run it with F5 and do not want it to close window automatically - just add breakpoint on the return from main()
    Even without debugging it keeps close the window... god dam

    any suggestions?

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    sonjared made a suggestion in post #5 that was seconded by Adak in post #6. Have you tried it?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    May 2013
    Location
    Rishon Le Siyon, Hamerkaz, Israel, Israel
    Posts
    13
    can't find where linker > system is ...
    here's a snapshoot:
    View image: snap

  13. #13
    Registered User
    Join Date
    May 2013
    Location
    Rishon Le Siyon, Hamerkaz, Israel, Israel
    Posts
    13
    nevermind guys i got this figured ... just created a new project and set it to Empty with the Console type probably was the mistake on the last one... thanks to everyone who tried to help this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello, I am a newbie and so I have a newbie question;)
    By piratemonkey247 in forum C Programming
    Replies: 4
    Last Post: 12-20-2012, 10:59 AM
  2. Newbie Question...
    By electrondec in forum C Programming
    Replies: 2
    Last Post: 09-23-2008, 11:21 AM
  3. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  4. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM
  5. Another newbie question
    By SuperNewbie in forum C# Programming
    Replies: 0
    Last Post: 02-09-2003, 02:28 PM

Tags for this Thread