This project has been created as part of the 42 curriculum by dporhomo.
Exam02 is a comprehensive exam preparation repository from the 42 curriculum designed to master intermediate-to-advanced C programming concepts. This project encompasses 60+ exercises organized across four difficulty levels, progressing from fundamental string manipulation to complex algorithms and data structures.
The exercises are designed to be solved without standard library functions (with minimal exceptions like malloc, atoi, and free), forcing deep understanding of C fundamentals and algorithm design.
Project Status: β Completed: All 4 Levels
The 4-level structure ensures a smooth learning curve:
- Level 1 (13 exercises): Basic string manipulation and character operations
- Level 2 (20 exercises): String functions, bit manipulation, and simple algorithms
- Level 3 (16 exercises): Dynamic memory allocation, linked lists, and mathematical algorithms
- Level 4 (13 exercises): Complex data structures, sorting, and advanced pointer manipulation
- Level 1: βββββββββ Basic (13 exercises)
- Level 2: ββββββββββ Intermediate (20 exercises)
- Level 3: ββββββββββ Advanced (16 exercises)
- Level 4: ββββββββββ Expert (13 exercises)
- Length calculation, copying, comparison
- Searching and replacing
- Case conversion and character transformation
- Word extraction and parsing
- Printing and reversing bits
- Swapping individual bits
- Power-of-2 detection
- Bit masking and shifting
- malloc() and free() usage
- Pointer arithmetic
- 2D array allocation
- Memory leak prevention
- Linked lists (creation, traversal, deletion)
- Arrays and multidimensional arrays
- Character arrays and string arrays
- String algorithms (intersection, union, matching)
- Mathematical algorithms (GCD, LCM, primes)
- Sorting algorithms (insertion, bubble, merge)
- Base conversion and number systems
- Function pointers and callbacks
- Variadic functions (va_list)
- Command-line argument processing
- Static variables (in some exercises)
Level 1: Master C fundamentals through string manipulation
- Pointer syntax and dereferencing
- String indexing and iteration
- Character operations
Level 2: Understand standard library functions and bit operations
- Implement libc functions from scratch
- Master bitwise operations
- Learn string algorithms
Level 3: Work with dynamic memory and data structures
- Allocate and free memory safely
- Implement linked lists
- Solve mathematical problems
Level 4: Advanced data structures and algorithm optimization
- Sort complex data structures
- Use function pointers effectively
- Handle nested dynamic allocations
Each exercise is self-contained and can be compiled individually:
# Compile a single exercise
gcc -Wall -Wextra -Werror Level1/ft_strlen.c -o ft_strlen
# Run the exercise
./ft_strlenFoundational exercises covering essential C skills.
| File Name | Description | Key Function/Concept |
|---|---|---|
ft_strlen.c |
Returns the length of a string | ft_strlen(char *str) - String length calculation |
ft_strcpy.c |
Copies one string to another | ft_strcpy(char *dest, char *src) - String copying |
ft_putstr.c |
Prints a string to stdout | ft_putstr(char *str) - String output |
ft_swap.c |
Swaps two integer values | ft_swap(int *a, int *b) - Pointer manipulation |
repeat_alpha.c |
Repeats each letter by its alphabetical position | Character repetition logic (a=1x, b=2x, c=3x, etc.) |
first_word.c |
Prints the first word of a string | String parsing and word extraction |
last_word.c |
Prints the last word of a string | String parsing from the end |
ulstr.c |
Converts uppercase to lowercase and vice versa | ft_islower(), ft_isupper() - Case conversion |
rot_13.c |
ROT13 cipher encoding | Character transformation (rotate by 13 positions) |
rotone.c |
Rotates each character by one position | Character rotation logic (aβb, zβa) |
search_and_replace.c |
Replaces one character with another | Character search and replacement in string |
rev_print.c |
Prints a string in reverse order | String reversal algorithm |
fizzbuzz.c |
Classic FizzBuzz algorithm | Loop control and conditional logic |
- Pointer fundamentals
- String iteration and indexing
- Character-level string manipulation
- Basic loop and conditional logic
Exercises focusing on function recreation, string algorithms, and bit-level operations.
| File Name | Description | Key Function/Concept |
|---|---|---|
ft_strcmp.c |
Compares two strings lexicographically | ft_strcmp(char *s1, char *s2) - String comparison |
ft_atoi.c |
Converts string to integer | ft_atoi(char *str) - String to int conversion, sign handling, whitespace |
ft_strdup.c |
Duplicates a string with malloc | ft_strdup(char *src) - Dynamic memory allocation, string copying |
ft_strrev.c |
Reverses a string in place | String reversal with pointers |
ft_strspn.c |
Finds length of initial substring | ft_strspn(char *s, char *accept) - Character set matching |
ft_strcspn.c |
Finds length before character in set | ft_strcspn(char *s, char *reject) - Character exclusion |
ft_strpbrk.c |
Finds first occurrence of character in set | ft_strpbrk(char *s, char *accept) - Pointer arithmetic, early return |
do_op.c |
Performs arithmetic operations based on input | String operators (+, -, *, /, %), atoi() usage |
max.c |
Finds maximum value in array | Variadic function arguments handling, va_list |
inter.c |
Shows intersection of two strings | Array manipulation, character lookup, duplication |
union.c |
Shows union of two strings | Character set operations, avoiding duplicates |
wdmatch.c |
Matches word pattern in string | Advanced string matching, character validation |
camel_to_snake.c |
Converts camelCase to snake_case | Character case detection and conversion |
snake_to_camel.c |
Converts snake_case to camelCase | String transformation, case switching |
alpha_mirror.c |
Mirrors alphabet positions | Character mapping (aβz, bβy, etc.) |
is_power_of_2.c |
Checks if number is power of 2 | Bitwise operations (& operator), mathematical property |
print_bits.c |
Prints binary representation of number | Bitwise operations and loop control, bit shifting |
reverse_bits.c |
Reverses bits of a byte | Bit manipulation, shifting (>>, <<), masking |
swap_bits.c |
Swaps two bits in a byte | Bitwise operations (|, &, >>, <<), bit extraction |
all_bits.c |
Checks if all bits are set | Bitwise AND operations, comparison logic |
- Standard library function recreation
- Bitwise operations and bit manipulation
- String algorithms and parsing
- Memory allocation with
malloc - Variadic function arguments (
va_list)
Exercises introducing dynamic arrays, linked lists, and complex algorithms.
| File Name | Description | Key Function/Concept |
|---|---|---|
ft_range.c |
Creates array of consecutive integers | ft_range(int start, int end) - Memory allocation, array filling, range logic |
ft_rrange.c |
Creates array in reverse order | Reverse range generation with malloc, descending iteration |
ft_atoi_base.c |
Converts string to integer in any base | Base conversion algorithm (2-36), modular arithmetic |
ft_lst_size.c |
Counts elements in linked list | Linked list traversal, struct pointer iteration |
ft_list.h |
Linked list structure definition | Data structure definition with t_list |
hidenp.c |
Checks if string is hidden in another | Pattern matching algorithm, character-by-character validation |
expand_str.c |
Expands spaces to three spaces | String expansion with malloc, character insertion |
epur_str.c |
Removes extra spaces from string | String cleanup and normalization, whitespace handling |
str_capitalizer.c |
Capitalizes words in string | Word boundary detection, state machine |
rstr_capitalizer.c |
Reverse string capitalizer | Complex string manipulation, backward iteration |
tab_mult.c |
Prints multiplication table | Formatted output, nested loops, printf formatting |
print_hex.c |
Converts number to hexadecimal | Base conversion to hex, modulo operations, digit mapping |
pgcd.c |
Calculates GCD (Greatest Common Divisor) | Euclidean algorithm, recursion or iteration |
lcm.c |
Calculates LCM (Least Common Multiple) | Mathematical algorithm using GCD formula |
paramsum.c |
Sums all command-line parameters | argc, argv handling, atoi() conversion |
add_prime_sum.c |
Sums all prime numbers up to n | Prime number algorithm, optimization techniques |
- Dynamic memory allocation and deallocation
- Linked list fundamentals
- Base conversion algorithms
- Complex string parsing
- Mathematical algorithms (GCD, LCM, primes)
- Command-line argument processing
Advanced exercises covering complex data structures, sorting algorithms, and function pointers.
| File Name | Description | Key Function/Concept |
|---|---|---|
ft_split.c |
Splits string into word array | ft_split(char *str) - Dynamic 2D array, malloc/free, word parsing |
ft_itoa.c |
Converts integer to string | ft_itoa(int n) - Number to string conversion, sign handling, digit reversal |
ft_strmapi.c |
Applies function to each character | Function pointers, callback pattern, character transformation |
sort_int_tab.c |
Sorts integer array | Bubble sort or quicksort implementation, comparison logic |
sort_list.c |
Sorts linked list | Linked list sorting algorithm, node swapping |
sort_list.h |
Linked list structure for sorting | Data structure definition with comparison |
ft_list.h |
Generic linked list structure | Struct definition with pointers, node architecture |
ft_list_foreach.c |
Iterates function over list elements | Function pointers, list traversal, callback execution |
ft_list_remove_if.c |
Removes elements matching condition | Conditional node deletion in linked list, memory freeing |
lst_all_full.c |
Complete linked list implementation | Comprehensive list operations (add, remove, sort, iterate) |
rev_wstr.c |
Reverses order of words in string | Word-level string manipulation, array of pointers |
rostring.c |
Rotates words in string | String rotation algorithm, circular shift logic |
fprime.c |
Factorizes integer into primes | Prime factorization algorithm, divisor iteration |
- 2D dynamic arrays and string arrays
- Function pointers and callbacks
- Linked list manipulation and sorting
- Complex pointer arithmetic
- Advanced memory management
- Prime factorization and mathematical algorithms