C/C++ Programming for Hackers: Part 2 (The History of C and Coding Our First Program).
Welcome back everyone! in this tutorial, i will talk a little bit about the history of the C programming language aswell as some famous programs that are programmed in this language (it is not really necessary to be able to code in C, but it's still nice to know!). after that, we will go ahead and write our very first program! i will also go in detail on every line and explain exactly what it does.
if you haven't read my previous article yet, you can do it here.
C was developed between 1969 and 1973 by Dennis Ritchie at AT&T Bell Labs, and was used to create the Unix operating system (which in turn forms the base of our trust worthy Linux kernel). since then, C has dominated the world of computer programming. it has influenced other programming languages like C++, C#, Java, Python, and many more.
now a little bit about some famous pieces of software written in C. here is a list of them:
- Windows (the applications that come with it such as the calculator are C++, but at it's core, Windows is still written in C)
- Unix (the operating system that keeps Google, Facebook and almost every other big website up and running. it wouldn't even surprise me if wonderhowto runs on some kind of Unix)
- Linux (since Linux is a re-engineered version of Unix.)
- Android (uses the Linux kernel.)
- Embedded Systems (C is a lightweight language, therefor it is favored to program embedded systems.)
- IOS and MacOSX (also uses some kind of Unix kernel.)
as you can see, C is an important language, especially for operating systems. but it is also interesting to us since quite a lot of hacking tools are written in C, like Bully, for example.
ok, enough lecture, let's code!
As i said earlier, i will use Ubuntu for this tutorial, but you can use any linux distro you want. once you have fired up Ubuntu, you can go ahead and open a text editor and paste this code in it.
once pasted, it should look like this:
simply save the file to any directory you want. But remember this directory, as we will need to point the compiler to it. save the file as main.c
MAKE SURE YOU NAME IT main.c the "main" file is always the start file of your program and the .c extension tells our compiler that it is a program written in C. i simply saved the main.c file in my home directory.
if you have the main.c file in your home directory, you can immediatly go ahead and enter this command:
if you saved the file somewhere else, you first need to move your terminal to that location using the cd command.
if everything goes alright, you should get no errors and there should be a new file in your directory named a.out.
to run the program, first check if you have execution permissions on your a.out file. to do this, open your file explorer > right click a.out > click on Properties > go to Permissions tab > check if "Allow executing file as program" is enabled.
now, just go into a terminal, go to the directory where a.out is saved, and enter the following command:
if the program outputs "Hello Null Byte!", congratulations! you've coded your first program!
that is it for now folks! in the next how-to, i will be explaining the code we just wrote, step-by step.
if you have any problems or questions regarding this tutorial, feel free to ask me in the comments bellow!