C Programming

02.03.01, Mathematics and Artificial Intelligence



You have a lecturer from the Department of Software Engineering, but probably have not yet completed the survey 'Let's get acquainted'? This is a very dangerous situation. Don't wait for (and if) the instructor to say. Fill in!


Distant Learning

  • MS Teams team code: 6v9salf and link



0. Git repository

  1. Number guess. You should define a range, e.g. 1 to 1000. The program should ask user to think of a number. Then the program should ask the user repeatedly if the number is greater than some X, than Y, etc. until it guesses a number. Then it should print the number out. Note that you are free to decide if to split your range by 2 each time or widen it to the power of 2 first, and the program should always ask the same question like 'is is greater than X', but, if you do not like asking about greater you can ask about 'less than X' — it will finally make no difference =).

  2. Change 04.Arrays_Strings/arrays2.c (or arrays3.c if you have large CPU cache) a tiny bit to slow it down dramatically by causing a cache thrashing.

  3. Reproduce string input overflow in 04.Arrays_Strings/string_overflow.c. Fix it by any mean (like you saw during classes or other means).

  4. Starting from 05.Pointers/pointer3.c in examples, calculate a room for all the command line arguments, then concatenate them and print as a single string.

  5. Port 06.Structs_Unions/floating_fields.c example for double precision floating point numbers.

  6. Basing on 07.Modules and your previous tasks create any two programs, which use shared object or statically linked shared module.

  7. Finish 08.IO/binary.c to not only write, but also read binary data from a file.

  8. Get inspired by 09.Tools/ exaple and create a proper makefile for any of your multi-module program. Using makedepends for header dependency scan and creating IDE projects are possible, but not required.

  9. Linked list: implement 3 missing functions in 10.List/list.c, add some code to prog.c to test them.

  10. Searching and Sorting: Use 11.Sort_Search example, add global counter to increment in compare_persons function, and count (and show), how many times comparison was invoked when sorting and searching. Replace qsort with either heapsort or mergesort (or implement somewhat like bubblesort yourself =)), compare results.

  11. Basing on 13.Faster_Python_C/2.CFFI/ example, re-implement this pseudorandom generator in C and make it accessible from Python. Compare the speed (it should not differ very much for single pseudorandom generated).

  12. Completely optional =). Basing on 14.Cross_Compiling/ZX_Spectrum/ example, port any of your programs (or create new one) to either ZX Spectrum or any other retro platform.

Agenda Draft

  1. C Programming language reasoning and history. Operating enviroment: generic Unix-like (Linux), others (Windows + Cygwin,MSYS2,MSVC). 'Hello World' program.

  2. Built-in data types: char, int, float, double. Control flow: operators, functions, comments, cycles.

  3. Macros. Arrays and strings. Pointers. Character encodings.

  4. Structures and unions. Bit fields.

  5. Module system. Includes. Libraries.

  6. Input and output. Standard library modules.

  7. Utilities: 'make'; IDEs; debuggers; profilers.

  8. Dynamic memory allocation, heap. Memory leaks.

  9. Sorting and searching arrays.

  10. Trees and graphs.

  11. C and Python. CFFI, Python.h.

  12. pkg-config. Cross-compiling C programs.


  1. Ivor Horton. Beginning C. From Novice to Professional. APress: 2006.

  2. Jeri N. Hanly, Elliot B. Koffman. Problem Solving and Program Design in C. Pearson Education: 2007.

  3. Kyle Loudon. Mastering Algorithms with C. O'Really: 1999.

  4. Brian W. Kernighan, Dennis M. Ritchie. The C Programming Language. Prentice Hall: 1988

C Programming