student@ubuntu:~$
c 5/5 50 XP

Synthesis

0%

Quick Reference

Project structure checklist:

project/
  Makefile          # Build automation
  main.c            # Entry point
  module.h          # Interface (prototypes, types)
  module.c          # Implementation
  tests/            # Test files

Error handling pattern:

FILE *f = fopen(path, "r");
if (f == NULL) {
    perror("fopen");
    return -1;
}
// ... use f ...
fclose(f);

Cleanup pattern (goto for error handling):

int result = -1;
char *buf = calloc(n, sizeof(char));
if (!buf) goto cleanup;
FILE *f = fopen(path, "r");
if (!f) goto cleanup;

// ... work ...
result = 0;

cleanup:
    if (f) fclose(f);
    free(buf);
    return result;

Common Pitfalls

  • Resource leaks on error paths – Every early return must free all previously allocated resources.
  • Missing error checks – fopen, calloc, fork, exec can all fail. Unchecked failures cause crashes or corruption.
  • Tight coupling – Modules that depend on each other’s internals are fragile. Design clean interfaces.
  • No Makefile – Manual compilation doesn’t scale. Always write a Makefile.

Unlocks

Complete this skill to see what it unlocks.