This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Lab01 - Introduction to the Computer Laboratory and C Programming Language

  • Introduction to the computer environment - password settings and eventually ownCloud setup
  • Introduction to the working environment - terminal control and elementary commands: ls, cd, pwd, mkdir, cp, mv, rm, touch, and man. Further commands such as locate, cat, hexdump and find.
  • Download souces from the 1st lecture be5b99cpl-lec01-codes.zip
  • Compile the first program be5b99cpl-lec01-codes/program.c

clang -Wall -pedantic -std=c99 program.c -o main
gcc -Wall -pedantic -std=c99 program.c -o main
* Compile and executed the program lec01/var.c

  • Setup your working environment, e.g.,

clang var.c && ./a.out

  • Test to executed the program as in the lecture example

clang var.c -o var
./var; echo $?
./var 1 2 3; echo $?
./var aaa; echo $?

  • Compile the code with -E and -S options
  • Evaluate the executable binary in dynamically and statically linked, use the strip tool to reduce the program size. Evaluate -OS compiler flag.
  • Become familiar with your selected favorite editor for editing sources, e.g., gedit, sublime, vim.

For the gedit, you cannot configure the formatting of the source according to the CPL recommendation coding style using clang-format using script available in the archive setup_gedit.zip. You can download the archive, unzip the file, and execute the script as follows:

wget http://cw.fel.cvut.cz/wiki/_media/courses/be5b99cpl/labs/setup_gedit.zip
unzip setup_gedit.zip

Lab tasks

  • Test sizes of the numeric data types lec01/types.c, lec01/points.c
  • Write simple macros for defining symbolic constant as a nested expression (using other macros).
  • Evaluate the defined macros defined with and without enclosing brackets
  • Become familiar with the program lec01/main_env.c
  • Write a simple program to parse a single value using scanf() and report message to stdout and stderr
  • Write a simple program to parse a sequence of numbers using scanf() and printf(), read integer values and report average values computed to 2 decimal places.
  • Write a program that reports information about the passed arguments to the program (argc, argv)
  • Write a simple program to read characters from stdin using getchar() and write them to stdout using putchar(). Consider the program for copying files.

Further tasks

Implement programs in exercises and programming Projects of Chapters 2 and 3 of the K.K. King textbook.

courses/be5b99cpl/labs/lab01.txt · Last modified: 2018/10/04 15:47 (external edit)