2017/08 - "Hello World" in C, but it's 2017

C is a pretty old language, now almost entirely rendered obsolete by C++ to the best of my knowledge. My interest in learning C is that it's kinda like an old grandfather. I believe working with C is necessary in order to appreciate what Java, Python, Rust, and so forth, give us. And I'm honestly just plain curious what this old dinosaur felt like to program with "back in the day", and thought that installing C and figuring out how to make a hello world program with it would be pretty cool.

I'm not an expert in C, so please bear that in mind as you read. I simply enjoy writing about what Ive learned and have found it to be a great way to retain information. That and I also think that in order to be happy in life, you've got to give something back to the community that you're a part of. I want to make this a kind of "living article" that I slowly add to, week-by-week, until it is finished.

So without further ado, let's get crackin!


Step 1: Installation

The quickest way I've found to install C is to use Minimalist GNU for Windows, or MinGW for short. Go here, click download and select the next download button next to "MinGW - Minimalist GNU for Windows":

Next, you need to run the executable you just downloaded. You really just want to select all the default options here so I'm not going to upload images of this in order to save space. You just click "Install","Continue", (wait a few seconds), "Continue" again, then you get to pick a few packages. Select the developer toolkit and base package, then click on installation followed by apply:

It'll ask you to apply your changes again, so just go ahead and select "Apply". Once its finished, close the windows. Next, we'll have to update our path environment variable so that it knows about MinGW. You can do this by typing "environment" into your search bar and selecting "Edit the system environment variables". Alternatively you can find this option under your control panel. Click on the "Environment Variables" option when you find the right window, then open up the "Path" system variable:

Edit it by clicking the edit button, then add the MinGW directory:

Click okay, apply all changes, and you're almost done! Lastly, we have to check that it's actually working. Open up the command prompt and type in "gcc -v". If you see something like the below image, you successfully installed an antiquated language! Congratulations! 

Step 2: Hello World

Thenext thing we'll want to cover is the creation of a basic hello world program. Despite C's reputation as some kind of "monolithic, impossible-to-ever-use-without-breaking-your-computer, dinosaur" reputation, it is not quite as hard as one would think. Create a C file called "tutorial" (Create a text file, then put ".c" at the end of the filename and save it under "all files") and write the following code inside the file:

#include <unistd.h>
#include <stdio.h>

int main()
    printf("Hello World!");
    sleep (1);

In your command prompt, type "gcc tutorial.c" to compile the program. Then run the resultant executable file from this command. You should see the following, for a split second:

So congratulations again! You just wrote your first PROGRAM in C! What more can you accomplish in one day?! Well, we could try to deconstruct exactly what we just typed out in order to learn a little bit more about C.


So that's how you make a C program in 2017! Now that you have a foothold in the language, you could try something a little more complex. You could try creating a CRUD app for example, or I could just cover it in a later tutorial when the mood takes me. 

Good luck for now!