42 | Exam Rank 03

It helps to understand why 42 designed Rank 03 this way. In Rank 02, you implemented ft_split, ft_itoa, etc. — pure string manipulation. These functions run in user memory only.

Rank 03 introduces system interaction:

Suddenly, your code is no longer deterministic in a simple way. It depends on the state of the kernel, the file descriptor table, and the read buffer. You must now think about edge cases that come from the outside world, not just from string inputs.

A program that takes a positive integer and displays its prime factors. 42 Exam Rank 03

The logic can be broken down into a simple state machine within a loop.

This is the most common starting point. The task is to take a positive integer as an argument and print the smallest number composed of the exact same digits that is larger than the input.

Example:

You cannot simply "check" if a number is next; you must calculate it.


Do not segfault. The exam grading script will throw unexpected inputs at you.

One thing that fails 80% of students in Rank 03 is failing to close file descriptors. It helps to understand why 42 designed Rank 03 this way

If you open a file (for get_next_line) or have pipe ends hanging (for shell), the exam grader will flag a "Fatal Error" or "File Descriptor leak."

The Golden Rule: For every fork(), there is a wait(). For every open(), there is a close(). For every malloc(), there is a free().