Section 0h

Installing C in a Windows Environment


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Working in Windows

As you have noticed, like many other programming languages, you can use the C language in several different systems.

This page will show you how to use C in Windows. You will actually use a compiler commonly associated with Linux called GNU, inside a package called MinGW (Minimalist GNU for Windows). Let's get started.

Downloading and Installing MinGW

Open a browser and go to https://sourceforge.net/projects/mingw/ to access MinGW (Minimalist GNU for Windows). The following will be displayed. Select the green Download button.

MinGW Site

This will lead to the following screen.

MinGW License

View the licence as needed and select Install.

MinGW License

You can leave the configuration as is and select Continue.

Downloading window

Again leave the configuration as is and select Continue.

Installation directory

Select all the options as shown. None of these require very much hard drive space.

MinGW Installation Manager

Once all the options have been checked, go to Installation, and select Apply Changes as shown here.

MinGW Installation Manager

This leads to the verification window where you can select Apply.

Schedule of Pending Actions

The download process will engage as shown here.

Download package

After the downloads, the files will be extracted as shown here. When completed, you can select Close.

Applying scheduled changes

At this point, you can verify that all the boxes are green.

Installation manager

Now go to your File Explorer, as shown.

File explorer

Go to your C: Drive, shown here on the left.

C: Drive

Double click on the MinGW directory as shown.

C: Drive

Double click on the bin directory, shown here.

Directory

Click in the top bar to show the path of the bin, as shown here. Press Ctrl-C to copy this.

File path

Now right click on the Windows Start button in the lower left corner, and select System as shown.

Select system in lower window

Type Environment in the query box, upper left, and select the Edit the system environment variables item that is displayed.

Search for environment

Select the Environment Variables… button, shown here.

System properties

Double click on the Path item, shown here.

Environment Variables

Select the New button, shown here.

Edit environment variables

Type Ctrl-V to paste the MinGW bin path into the line, as shown here, and then select OK.

Edit environment variables

Again, select OK, as shown here.

Edit environment variables

And select OK one more time, as shown here.

System properties

This should take care of your setup but it is worth verifying. In the search bar at the bottom of your Windows screen, type cmd, as shown here.

cmd

In the command line window, type gcc --version as shown here.

command line

When you press enter, you should see the following. This verifies that you have MinGW installed and configured correctly, as shown here.

command line

Finally, you need to configure your workspace.

You can create a workspace immediately under your User directory by typing mkdir Projects or whatever you like. However, don’t place any spaces in the directory name. You could use CS136_Projects but don’t use CS 136 Projects as there may be problems with this later on.

Here is an example of creating a directory as described.

command line

If you type dir here, you will see the directory you created, as shown.

command line

If you type cd CS136_Projects, this will move you to that directory, as shown.

show directory

As you create your projects, you should start a new directory under your projects directory for each one, using the same process described. Here is a example.

show directory

You move to that directory the same way as you moved to the projects directory, as shown.

show directory

Finally, you are now ready to test your compiling process. Create a file using Notepad, as shown here.

command line process

Save the file to your project location, as shown here.

save file

Now go back to your command line by typing cmd in the search bar at the bottom of your screen, shown here.

command prompt

Navigate to your working directory, as shown here.

command line

Type dir to verify the file is there, as shown.

verify file

Now type gcc -Wall testprog.c -o testprog.exe as shown. Unless you have warnings or errors, nothing is displayed but the prompt returns as shown.

compilation

Now type testprog and watch the fireworks!

fireworks

Once you have done this, you are ready to get to work on your programming. Enjoy!