1. Codespace kickstart
To get started with GitHub, you'll need to create a free personal account and verify your email address. For this go to GitHub type a valid e-mail address (you will need to verify, if you have an edu.bme.hu e-mail address, it will fit, if you don't just add one that you can reach) and press the sign up button


Now you have to wait a few seconds for the verification code sent to your mail address to arrive, if it arrives it will contain a few numbers as in the next screenshot. Copy the numbers to the new tab appeared in your browser:



- Copy the https://github.com/nemmarton/Laboratory_1 to the URL section
- Give a respository name (Lab1 is OK for you too)
- Click on Begin import as on the screenshot




The codespace free tier is for free up to 60hrs for a month, which is enogh for us to learn and practice, but you need to stop the virtual macine! for that when you finishes your session switch tab to github and stop the codespace as in the screenshot:

Let's try out if our main.c compiles or not. For this navigate to the main.c on left, click on main.c, and the content will appear on the main window. Push the "play" button on the right corner. On the bottom we can see messages from the compiler, when everything is OK, you can switch to colsole view among the bottom tabs. If everything is all right, Hello will appear before the other messages:

2. Using the terminal

1. Open the Terminal
You will use the integrated terminal instead of CMD (windows).
- use the bottom tab to switch to terminal
- Shortcut: Ctrl + ` (backtick, under Esc key)
- Or: Menu → Terminal → New Terminal
2. Useful Terminal Commands
ls # list files in current directory
cd foldername # change directory
cd .. # go up one folder
mkdir newdir # create a folder
cat file.txt # display a file's contents
nano file.c # open a simple editor to create/edit files
clear # clear the terminal
3. Verify GCC
In the terminal, check GCC is available:
gcc --version
4. Compile and Run C Code
Suppose your file is main.c
:
gcc main.c -o main # compile
./main # run
5. Example Workflow
You can copy-paste the commands# Create a new C file
nano hello.c
# Inside nano, write:
#include <stdio.h>
int main() {
printf("Hello Codespaces!\\n");
return 0;
}
# Save and exit (Ctrl+O, Enter, Ctrl+X)
# Compile
gcc hello.c -o hello
# Run
./hello
6. Input/output redirection in the terminal using the wc
(word count) program.
Step 1: Count Words and Lines
Use wc
with input redirection:
wc < README.md
It shows: line count, word count, character count.
Step 2: Save the Output
Redirect the result into a new file:
wc < README.md > results1.txt
Now check the contents of results1.txt
:
cat results1.txt
Step 3: Create a Second File
nano text2.txt
Write 3–4 lines of text, then save and exit.
Step 4: Append Results
Append the results for the second file into results1.txt
:
wc < text2.txt >> results1.txt
Verify:
cat results1.txt
Step 5: Count Multiple Files
You can also pass multiple files at once:
wc README.md text2.txt
The cursor is blinking behind the prompt. By default it is built of the current directory and a $
symbol. Prompt means you are to type a command to the OS!
To list the content of the actual directory (folder):
ls
The list contains further folders and files.
The ls
command can interpret several command line parameters (switches). For help type:
ls --help
Most Unix-like OS commands give help like this.
Changing the current directory
To change directory use the cd
command. Change to the parent directory:
cd ..to get back:
cd Lab1
The folder names in the hierarchy are separated by a / (slash) in the path. Windows also supports the UNIX style / separator.
Creating and deleting folders
To create a new folder type mkdir
or md
:
mkdir clab
To delete a folder type rmdir
or rd
:
rmdir clab
The folder remains intact if it contains files.
Certain commands, like ls
interpret filenames containing wildcard characters. The following command will only list files having .txt
extension.
ls *.txt
The ?
character matches any single character, the *
character matches any number of arbitrary characters in a filename. Like: ls x*e
list files starting with x, ending with e. There can be several wildcards in a name: dir x*py*e
. Using the question mark:
ls README.??
.
6. Painting
Task: Write a program that calculates how many cans of paint must be purchased to coat every (outer) surface of a cylindrical container. You must define variables of appropriate type, read in and print out values.
The height and the diameter of the cylinder is known. Yield of the paint: one can of paint is sufficient for a surface area of 2 m2.
Paint the container Height? 2 Diameter? 1.2 4.900885 can(s) of paint needed.
You can use an approximate value of 3.14159265
for Pi. If your program delivers different result re-check your formulae.
Format of the printout
A millionth of a can is not relevant but rather disturbing piece of information. To make the printout human friendly it is wise to round the printed value to one decimal digit following the decimal point: in printf
change %f
to %.1f
.
4.9 can(s) of paint needed.
7. \n and %d
Start a Hello World program. Modify the printed text:
printf("Hello\nworld\n\n!");
What happens?
What happens when using two backslash characters \\
?
printf("Hello world!\\n");
Print out the patterns below using one single printf()
statement in each case.
/ / /
\ \ \
printf("hello\n") will print "hello", and starts a new line.
Using "%d" we can print the value of an integer variable.
8. Further problems for practicing
Task: scanf in C
Create a C program that practices the usage of scanf with the %d format specifier.
The program should follow these steps:
- Declare variables to store the two integers.
- Prompt the user to enter the first integer.
- Read and store the entered value using scanf with %d.
- Prompt the user to enter the second integer.
- Read and store the entered value using scanf with %d.
- Calculate the sum of the two integers.
- Calculate the product of the two integers.
- Display the sum and product using printf. For example:
#include <stdio.h>
int main() {
// Declare variables
// Prompt the user to enter the first integer
// Read and store the first integer using scanf with %d
// Prompt the user to enter the second integer
// Read and store the second integer using scanf with %d
// Calculate the sum of the two integers
// Calculate the product of the two integers
// Display the sum
// Display the product
return 0;
}
Money
Creat a program that asks the user how many 50, 100 and 200 Ft coins does he have in his pocket. The program should then calculate how much money he has.
Celsius–Fahrenheit
Create a program that asks the user a real number, a temperature value in Celsius. The program should print the temperature in Fahrenheit (0°C=32°F, 40°C=104°F, linear)! Write the other way converter, too!