Thread: Newbie question

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    4

    Newbie question

    Hi. I am totally new to C programming and have been reading through a few books to try and pick it up. I have programmed in coldfusion mostly before and find a few similar things in c.

    My question is I have been coding and compiling some of these test projects in the book. Are all C programs developed to be accessed from a command prompt?

    This seems weird and the question might not make sense but how would you develop a 'standalone' program?

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I do believe the compiler, by default, suppose to generate an executable file.

    what compiler and system do you use?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Are all C programs developed to be accessed from a command prompt?
    No. The command prompt is just a shell around the operating system used as a text based interface with the user. Many programs these days run in their own graphical Windows.

    >how would you develop a 'standalone' program?
    What do you mean by standalone? Most programs are run on a hosted implementation and thus have the benefit of an operating system to load the executables into memory and do all of the bookkeeping.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    4
    I am using Visual C++ to compile. By standalone I was referring to a .exe file. When I compile, an .exe is built but when I try to run it, it flashes through DOS. (Dos loads quickly then disappears). How can I run this exe by itself?

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How can I run this exe by itself?
    You are running it by itself. But it needs a window to run in, so it creates a temporary command prompt. If you want the program to run in the background then you'll need to create a Win32 application and simply make the window invisible. But such a program is beyond the scope of this forum. You can ask in the Windows Programming forum though.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    4
    Is there a reason why Visual C++ creates all of these extra files (.plg, .ncb, etc) and also why does it create a 'Debug' folder where it places the .exe file. Is this how it normally compiles or is there a way to change this?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Those extra files and folders are support for Visual Studio. To run the program you really only need the executable and any files it requires (such as files you open with fopen).
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    4
    Prelude, You are right. I tested that out by moving the exe to the desktop and running it and it works but exits prematurely (i will need to fix the code for that I assume).

    What other compilers are recommended for C? Id rather not have extra files cluttering space.

    Thx!

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What other compilers are recommended for C?
    GCC is usually highly recommended.

    >Id rather not have extra files cluttering space.
    If you use an IDE on top of the compiler then you'll generally have extra files. However, a command line compiler isn't as user friendly in terms of a pretty GUI to work with.
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Quote Originally Posted by geomark
    When I compile, an .exe is built but when I try to run it, it flashes through DOS. (Dos loads quickly then disappears).
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

  11. #11
    Registered User
    Join Date
    May 2004
    Posts
    5
    I assume your using the stdafx.h header file when your compiling your programs in VC++. You can add a line of code that will wait until you press a key. add this line of code:

    Code:
    system("pause");
    This way it will run the program and pause until you hit a key.

    .ZG.

  12. #12
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Quote Originally Posted by geomark
    Prelude, You are right. I tested that out by moving the exe to the desktop and running it and it works but exits prematurely (i will need to fix the code for that I assume).
    It's not exiting prematurely. It's exiting upon completion. You can fix this in two ways:
    1) open a command prompt, navigate to the directory the .exe file is in, type the name of the exe file at the command prompt.
    2) just before the return at the end of your program, add getchar() for C or cin.get() for C++

    Don't use system("pause");
    It doesn't work for all systems, and it's not necessary to call the operating system to pause your program.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM