This project has been created as part of the 42 curriculum by acamelo.
C 02 deepens the exploration of memory by focusing heavily on string manipulation, memory mapping, and character classification. In C, strings are not native high-level objects; they are contiguous arrays of characters ending with a null-terminator (\0). Understanding how to duplicate, format, sanitize, and validate these arrays safely is a crucial milestone for secure software development.
Throughout this module, the objective is to replicate standard foundational routines from <string.h> (such as strcpy, strncpy, and string case toggles), while engineering low-level analytics engines that audit string formats. Additionally, it addresses the display of raw unprintable memory frames via hex manipulation, working entirely within the code constraints of the 42 Norm.
To compile and execute these programs, you require a standard C compiler (gcc or clang) installed within a UNIX-like environment.
Each exercise is isolated in its own directory and compiled independently. They contain an operational main.c layout to allow instant structural debugging.
- To compile a specific exercise using the standard 42 security flags:
cc -Wall -Wextra -Werror ft_strcpy.c -o test_program
- To run the generated binary executable:
./test_program
Every exercise targets a specific application of string parsing, layout validation, or data output conversions:
- **ex00:
ft_strcpy.c**– Replicates the standardstrcpyfunction. It copies a source string into a destination buffer pointer, moving character-by-character until it duplicates the null-terminator. - **ex01:
ft_strncpy.c**– Replicatesstrncpy. It copies up to$n$ bytes from a source string. If the source is shorter than$n$ , it pads the remaining space in the destination buffer with\0bytes to ensure predictable memory behavior.
- **ex02:
ft_str_is_alpha.c**– Scans a string to verify it contains exclusively alphabetical characters. It returns1if valid or if the string is empty, and0if it detects any symbol, number, or space. - **ex03:
ft_str_is_numeric.c**– Validates that a string consists entirely of numerical digits (0-9). - **ex04:
ft_str_is_lowercase.c**– Audits the target memory block to verify that all alphabetic letters are strictly lowercase. - **ex05:
ft_str_is_uppercase.c**– Audits the target memory block to verify that all alphabetic letters are strictly uppercase. - **ex06:
ft_str_is_printable.c**– Checks whether every character in the string falls within the printable ASCII range (decimals 32 to 126), catching hidden control characters or escape sequences.
- **ex07:
ft_strupcase.c**– Iterates through a string and modifies it in-place, transforming every lowercase character into its uppercase counterpart by adjusting its ASCII offset. - **ex08:
ft_strlowcase.c**– Performs the reverse operational logic of the previous exercise, converting uppercase characters into lowercase in-place.
A major security risk in low-level programming is handling uncontrolled string copies. While ft_strcpy assumes the destination buffer is pre-allocated with enough space, ft_strncpy introduces a size barrier (
Rather than building extensive lookup matrices to toggle character capitalization in ft_strupcase and ft_strlowcase, the conversion leverages a constant ASCII mathematical offset. Since the difference between any lowercase letter (e.g., 'a' = 97) and uppercase letter (e.g., 'A' = 65) is exactly 32, the transformation applies filter boundaries (if (str[i] >= 'a' && str[i] <= 'z')) and directly shifts the value (str[i] -= 32;), minimizing processing overhead.
-
Standard C Specifications (
man strcpy/man strncpy): Utilized to cross-reference exactly how edge cases—such as string length being equal to or greater than the character parameter count$n$ —should be handled down to the exact byte. -
ASCII Value Structural Tables: Used to map out character classification ranges for printable strings and alphabetic shifts without importing external headers like
<ctype.h>. -
Cluster Peer Feedback: Constant collaboration at 42 Madrid helped establish comprehensive edge-case validation suites, verifying that empty strings safely returned default true states (
1) across all validation tasks.
Artificial Intelligence was integrated into this project as a structural and educational advisor under the following rules:
- Algorithmic Boundary Reviews: Used to inspect nested safety loops inside string validations to ensure structural performance.
- Technical Editing: AI assisted in organizing, structuring, and polishing this technical
README.mdto guarantee a clean, professional look for engineering managers and recruiters at the Web Summit. - Note: Every single line of code was written manually, line-by-line, adhering strictly to the 42 Norm guidelines.