The C Programming Language (NPRG066)

NPRG066, MFF UK, summer semester 2023/2024.
Malá Strana, Mon 9:00, lab SU2.
Lectured by: Jan Pechanec, Vladimír Kotal
Department: SISAL
First class: Mon Feb 19, 2024

Overview

"Since C is relatively small, it can be described in a small space, and learned quickly. A programmer can reasonable expect to know and understand and indeed regularly use the entire language."

-- Brian W. Kernighan, Dennis M. Ritchie

The seminar is lectured in English unless everybody present can speak Czech. It is a recommended pre-requisite for Unix/Linux Programming in C (NSWI015).

Abstract

The hands-on seminar is meant to teach students how to program in C. It is targeting people who have no prior experience with the language. The seminar is not an introductory programming class. It assumes some familiarity with basic programming concepts like variables, assignment statements, loops, and functions. The C standards C90 and C99 will be covered. Strong emphasis will be put on writing real C programs taking advantage of all the language features discussed.

Target Group

This seminar is primarily targeting people who have no prior experience with the C language. However, all are welcome, and we believe everybody can learn something new in this class.

Development Environment

What you need for this seminar? Just a C compiler and a text editor. There are a few options:

  1. You can work directly on Linux desktops in the SU2 room. You will need your MFF UK unix login/password to get in. We assume you will know the minimum needed to use the system. Start a few terminals and that is all you need. The compiler is gcc. See below for a few editor options.
  2. Some Linux machines in the Malá Strana from the Rotunda lab are still remotely accessible via SSH with your unix MFF UK login. To log in, use e.g. ssh yourname@u-pl1.ms.mff.cuni.cz. You can also check ssh -M as that might come in handy to speed up multiple logins. Presently, due to the Rotunda lab ongoing reconstruction, there are only u-pl1 and u-pl10 machines available for an SSH login. Pick either of those, your home directory is mounted on both. You can use PuTTY client on Windows. Windows 10 already have OpenSSH. Then see the item above.
  3. Use your laptop with a GNU C (gcc) compiler installed, or any other modern C compiler. Any Linux distro, (Free|Net|Open)BSD, or a macOS machine will do but you may need to install the compiler there. On macOS, just run cc and follow the instructions there.
  4. Install a C compiler on your Windows laptop.
  5. Various combinations of the above in a virtual machine (e.g. open source VirtualBox runs on many platforms).

There is Eduroam WiFi available in the SU2 lab, you can connect to the lab machines from your laptops via SSH, see above.

Development Tools

We recommend to work from the terminal only, there is really no need for an IDE. We use ViM (on Linux distros and macOS as vi) and the compiler. If you are in the first year and did not go through the Unix intro lecture yet, the vi editor may not feel friendly at first, in that case Joe is a good alternative. It is also installed on all Linux lab machines as joe. You can also use GNU nano which is very easy to use as well.

If you can create a simple C program, compile it, and successfully execute the resulting binary a.out, you are good to go. For example:

$ cat main.c
int
main(void)
{
}
$ cc main.c
$ ./a.out
$ echo $?
0

Mailing List

Subscribe here to c-prog-lang-l mailing list hosted on mbox.ms.mff.cuni.cz.

We will use this alias for various announcements regarding the seminar. It is your responsibility to subscribe to it. And feel free to use it for technical discussion regarding the C language and what we do in the seminar.

Syllabus

Getting credits

To get credits, you complete a given assignment in C as a home project. The project submission is via sending us email with a link to an online repository we can use with Git or Mercurial (e.g. GitHub). You need to send the email to both of us, see the contacts below. Sending your code as an attachment will not be accepted.

We need to receive the email before the deadlines, anything after the deadline will not be accepted.

Tests to verify your implementation will be provided with the assignment. You must pass all the tests before handing over your solution. We will build your code and verify the tests on u-pl1.ms.mff.cuni.cz machine in the MFF UK lab at Malá Strana, see the Development Environment section above. If your code does not pass all the tests there, the submission will not be accepted.

You are supposed to write the code by yourself. Taking any existing code is strictly prohibited except for specific exceptions noted in the assignment.

The assignment has two phases. First has a deadline of Fri May 24, 2024, 23:59:59, CEST (= local Prague time), which is the end of the summer semester tuition period. The 2nd phase has a deadline of Sun Jun 30, 2024, 23:59:59, CEST, which is the end of the summer semester examination period. Please note that the deadlines are hard and failing them means you are forfeiting your chance to get the credits for this year.

You can submit the whole thing in one step before the first deadline, no need to separate the project in two parts.

If you need to finish your semester earlier (that may apply to Erasmus students), you need to finish the 2nd assignment in full before that.

The assignment for both phases.

FYI, our implementation of the 1st phase is about 400 lines of well commented code that conforms to the recommended C style. The 2nd phase is below 500 lines.

Seminar Notes

Seminar repository is work in progress. There is a direct link to the generated notes in Markdown format. A HTML version of the notes is provided as well.

C style for writing code

We strongly encourage you to use a good C style to follow when writing C code. It comes with a Perl script to check your style. We just cannot stress enough the importance of readable code with a unified look.

There are other indent styles to choose from.

References

Primary References

Supplementary References

Contact

vlada at kotalovi dot cz, jp at devnull dot cz


Last modified: