====== Lab01 - Introduction to the Computer Laboratory and C Programming Language ======
* Introduction to the computer environment - [[https://www.felk.cvut.cz/?setLang=en|password settings]]
* Introduction to the working environment - terminal control and elementary commands: ''ls'', ''cd'', ''pwd'', ''mkdir'', ''cp'', ''mv'', ''rm'', ''touch'', and ''man'', ''cat'', ''find'', ''grep'', ''wget'', ''unzip'', ''echo'', and input/output modificators: ''|'', ''>'', ''>>''.
* Compile the first program
* Test the executed program
* Become familiar with your selected favorite editor for editing sources, e.g., gedit, Sublime Text, Emacs, Vim.
===== Lab Code =====
**Exercise 1**
Simple program to output text:
#include
int main()
{
//this line is a comment, it will be ignored
printf("Hello World!");
return 0;
/*this is
multiline comment
*/
}
Practice compiling it:
gcc myprogram.c
GCC will take your code and produce a binary executable from it.
See if you can figure out:
How to customise your executable filename from gcc.
Make it format correctly in the terminal.
**Exercise 2**
We can use ''printf("here is an integer: %i", myint);'' to format an integer.
Similarly ''%f'' to format a float.
We can use ''scanf("%f", &fnum);'' to get a variable from the command line user.
Implement a function that calculates the Euclidean distance of two numbers.
That is, it takes two numbers, squares each of them, adds them, and returns the square root.
==== Basic terminal programs Help ====
Open terminal Ctrl + Alt + T
New tab Ctrl + Shift + T
End programs by running Ctrl+C
Close by Ctrl + D
=== man ===
Manual to (almost) every terminal program can be found using ''man'':
$ man
You shoud start working in linux terminal by asking, how to use manual
$ man man
=== pwd ===
To find out, where are you in the directory tree, the present working directory, use ''pwd'':
$ pwd
=== ls ===
To list files in your directory, use ''ls'':
$ ls
There is also possibility to see a content of different directory
$ ls
The useful parameters you should know are:
* ''-a'' do not ignore entries starting with ., usualy hidden files,
* ''-A'' the same as ''-a'' but it does not list implied . and ..,
* ''-l'' uses a long listing format,
* ''-p'' to append / at the end of the name of directories to differentiate them from files,
* you can also sort them by ''-S'' size, ''-t'' time, etc.,
* and combine them
$ ls -Al
=== cd ===
To change the directory use ''cd'':
$ cd
Go to the parent directory
$ cd ..
Go to the parent's parent directory
$ cd ../../
Go to the parent's parent directory and then to its child directory
$ cd ../../some_directory/
Go to the child's child directory
$ some_directory/some_subdirectory/
You can use absolute address:
$ /home/my_account/my_files/my_video/
There is also trivial way to your home directory:
$ cd
The manual is not presented, therefore use parameter ''--help'' to find out more
$ cd --help
For fast navigation, use keypad **Tab**. Use it frequently.
=== mkdir and touch ===
If you want to create a directory, use ''mkdir'':
$ mkdir
and ''touch'' for file creation:
$ touch
Please, do not use spaces in your names:
$ mkdir "I have come here from some advertising environment called Windows"
$ mkdir and\ I\ really\ like\ to\ troll
and if necessary, use ''_'' underscore instead:
$ touch I_love_linux
=== mv ===
Use ''mv'' for moving files or directories from one position in a directory tree to another:
$ mv