C programming question

How do you compile and run a C program from the DOS prompt? C not C++ (if that even matters). Do I have to edit the path in msconfig?

Do you have a C compiler?

In general, you install a compiler, and you run the compiler on your source code to produce an executable. For example, if you are using a command line compiler such as gcc and you have a program in foo.c, you’d run a command like “gcc foo.c -o foo.exe”, (the “-o foo.exe” meaning to use foo.exe as the output file), and voila!.. if everything worked right, you have foo.exe that you can run. If you want to use an IDE like Visual Studio, you’d create a project for your program, and add foo.c to the project, then set the project settings so that the compiled program is foo.exe, and hit “build”, and you get the same result.

As your projects get bigger, things get more complicated, but that’s a start.

DJGPP is a free compiler, and its installation instructions should tell you how to set up your paths so you can run it. I believe Cygwin also includes a compiler.

As others have said, you need a compiler…

One good free compiler for DOS/Win 9x is DJGPP. Newer versions will work with Win NT/2000/XP as well.

Can you edit, compile and run in it? I’m just looking for something more user friendly than the vi editor in UNIX (what isn’t?). Keep in mind I’m a broke student so free is a good thing.

Look for RHIDE. It’s a widely known and used IDE for DJGPP. It slightly resembles the old text-mode TurboC. It’s MUCH easier than vi. Its editor is pretty much a text-mode version of a modern windows-style interface.

Something else that’s easier than vi is Emacs. Emacs is a really nice text editor, like vi’s genius brother who is a freak about being user-modifiable. :smiley: It’s the main editor of the FSF’s GNU Project (You’ll learn who those guys are if you stick with developing C long enough, trust me. ;)) and it is a programmer’s dream, IMHO. There are plenty who agree with me. :slight_smile:

Emacs is good for programming because it has modes: In C mode, for example, it has syntax highlighting and auto-formatting, not to mention the ability to traverse the file by groupings of code (not just by line) and other things that generally make a hacker’s life easier. :slight_smile:

Emacs free for download. – A word of warning: Emacs is a chunk of code. If you are developing on a particularly small system or sitting on the end of a particularly slow connection, well, look at the filesizes before you click any links. Emacs includes a full programming language implementation (elisp) as part of the base package (Emacs is largely an elisp interpreter, actually), which does wonders for customizability and user-friendliness but makes it relatively worthless for severely limited systems. If running IE makes your processor palpitate, Emacs just might not be for you. :wink:

Emacs on Windows FAQ – Emacs also exists on MS-DOS, BTW.

I think you should download DJGPP from the website linked in above threads. The download procedure is called zip-picker and it has a list of check boxes you use. Simply say you want to compile and run C programs and also use the RHIDE IDE (Integrated Development Environment or visual way of writing programs and compiling them without using the command line).

It will give you a list of zip files to download. Download them, open them and away you go. Simple, effective and free.

BUT,

Getting back to the OP, when you install programs like this DJGPP compiler and others you often have to ‘edit the path’. This simply means that you have to tell the Operating System where the program you are running ( the compiler program) is located. So if it is in C:\DJGPP\BIN\ you need to add C:\DJGPP\BIN\ to the path.

This means that when you type in ‘cpp’ (the DJGPP compiler) the operating system looks for the file cpp.exe in the local directory, if it doesn’t find it it looks in the various PATH directories.

Type in ‘PATH’ at the dos prompt to see what you path is currently set to. To add C:\DJGPP\bin to the path you just add this line to your autoexec.bat

“set PATH=C:\DJGPP\BIN;%PATH%”

You should check out the Bloodshed Dev-C++ compiler+IDE.