Blog Post, Programming, Tutorials

Creating Your First C Program: Quickstart

Many can relate to the challenge of learning a new coding language. I’ve found that quickly being able to make a first program to start experimenting with the language helps inspire the confidence needed to keep going. In this blog post I will be briefly going over the steps needed to create a simple first program in the C language in Ubuntu.

Setting Up Your Development Environment On Your Computer:

  1. Install your favorite text editor; mine happens to be VS Code by Microsoft.
  2. Know how to use the cd and ls commands in the terminal to access the files you will be creating.

C is a compiled language which means that once you have written the .c file you will need to “compile” it which will create another file which the computer will use to run the program.

To install the GCC C compiler on your computer run:

$ sudo apt-get update # This is generally recommended in order to make sure that your system has up to date packages.
$ sudo apt-get install gcc # This installs the GCC C compiler to your system.
view raw gcc_install.sh hosted with ❤ by GitHub

To Create Your First Program:

Create a File with the .c file extension in your text editor. Below is a sample first C file.

// My "First" C Program:
// To Compile:gcc -o first_c_prg first_c_prg.c
// To Run:./firstc
#include <stdio.h>
#define EXIT_SUCCESS 1
int main(void)
{
char sentence[]= "Hello World!";
printf("%s\n", sentence);
return EXIT_SUCCESS;
}
view raw first_c_prg.c hosted with ❤ by GitHub

To Compile Your First Program:

Move to the directory that contains your program and type:

gcc -o first_c_prg first_c_prg.c
view raw Compile_C.sh hosted with ❤ by GitHub

This code has two important effects, it runs the gcc compiler and creates and names an object file from your program file.

To Run Your First Program:

In the same directory, type:

./first_c_prg
view raw Run_Simple_C.sh hosted with ❤ by GitHub

Please let me know if this helped you to get started quickly with C on Linux.

Blog Post, Programming, Tutorials

Creating your First Clojure Program in Linux

Those who really want to start learning a language will find it easier to start learning the language by setting up a REPL as fast as possible. This makes it easy to experiment with some simple expressions. This post will covers the installation of Clojure and an editor on Ubuntu Linux to set up a REPL.

Since Clojure runs on the Java Virtual Machine, one will need to install Java on your system. This, Here, is an easy way to do exactly that.

Now that Java is installed, one can install leiningen, a helpful tool for managing Clojure projects, especially when starting with Clojure.

To Install Leiningen:

Use Ubuntu’s package manager:

apt-get install leiningen

Or use wget:
wget puts files in your current working directory, which is home by default.

wget https://github.com/technomancy/leiningen
chmod +x lein # make executable. Make sure you are in the correct directory when you use this command
lein self-install

Installing a text editor:

Many people like using slime emacs for Clojure development, but for people who haven’t used emacs before I suggest using Nightcode. It is easier not to have to learn Clojure and a complex text-based editor like emacs at the same time. For this reason, Nightcode is a good alternative.

To install Nightcode download the .deb file and double click on it to open a window with the option to install it on your system.

Creating a New Leiningen Project:

In the terminal type:

lein new app first_proj

Lastly, open the project in Nightcode. A “Hello World!” console application is already generated for you.