Introduction to C Programming.
C is a procedural, compiled, platform-dependent language. It needs a compiler and GNU C Compiler is a popular one.
What we will do?
- Install GCC.
- Write C program.
- Compile and run it.
Install GNU C Compiler (GCC) depending on your Operating System.
-
Download Minimilastic GNU for Windows. After download,
-
After installation,
-
Add to environment variable.
- Environment variables > System Variables > Path
- Add
C:\MinGW\bin
. - Click OK > OK.
-
You can check in command prompt (cmd) by typing
gcc --version
for which you will get the output like:gcc --version gcc (MinGW.org GCC-6.3.0-1) 6.3.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Install GCC through either depending on your OS:
sudo apt-get install build-essential
or
sudo apt-get install gcc
Install GCC through homebrew.
brew install gcc
-
The theory/lessons are included in
lesson
. Each lesson is stored in a numbered sub-directory.- To view it online, click on the lesson directory on github.
- To view it offline, use any markdown reader to read the markdown files.
- Or, open it in vs-code > install
Markdown Preview
> open lesson directory > click on README.md > Press Ctrl+K & V to open markdown to the side.
-
The programs are included in
lab
in this repository. Each of the C program is stored in a numbered sub-directory. When you openlab
, the program list will be printed.-
Change directory to specific directory, say
0001
,cd lab/0001
-
To run the program, refer Section 3.
-
To switch betwen directories, say
0001
to1001
,cd ../1001
-
Say filename: hello.c
-
To compile it on Windows/Ubuntu/Mac,
gcc hello.c
-
This will create an executable
a.exe
on Windows. To run it,./a
-
This will create an executable
a.out
on Ubuntu/Mac. To run it,./a.out
-
To compile it on Windows:
gcc -o hello.exe hello.c
-
To compile it on Ubuntu/Mac:
gcc -o hello hello.c
-
After compilation, an executable file will be created (
hello.exe
on windows/hello
on Ubuntu/Mac). To run it,./hello
- On Visual Studio Code, go to Extensions and search for coderunner and then install it.
- Click play button on C file and it will be run automatically.
- If you need input from user, it will be compiled but not executed. (Refer to the other methods)