The project involves recoding the printf() function in C, allowing us to improve our programming skills by working with variadic functions.
The goal is to create a library, libftprintf.a, containing a custom ft_printf() function that mimics the original printf() in functionality but not in buffer management.
The project is designed to enhance programming skills and involves strict adherence to coding standards and proper memory management.
The function must handle various conversions, including characters, strings, pointers, integers, and percentages. Strict adherence to coding standards and proper memory management is required. Additionally, students can implement bonus features for extra credit, provided the mandatory requirements are perfectly met.
The custom ft_printf() function must support various format specifiers such as %c, %s, %p, %d, %i, %u, %x, %X, and %%.
To create a comprehensive test suite for ft_printf(), we need to cover all mandatory and optional features described in the project. Here are the relevant test cases for each format specifier and combination of flags:
-
Single Character
%c:ft_printf("Character: %c\n", 'A');should printCharacter: A.
-
String
%s:ft_printf("String: %s\n", "Hello");should printString: Hello.
-
Pointer
%p:ft_printf("Pointer: %p\n", (void *)1234);should print the pointer address in hexadecimal.
-
Decimal Integer
%dand%i:ft_printf("Decimal: %d\n", 1234);should printDecimal: 1234.ft_printf("Integer: %i\n", -1234);should printInteger: -1234.
-
Unsigned Decimal Integer
%u:ft_printf("Unsigned: %u\n", 1234);should printUnsigned: 1234.
-
Hexadecimal Integer
%xand%X:ft_printf("Hex (lowercase): %x\n", 1234);should printHex (lowercase): 4d2.ft_printf("Hex (uppercase): %X\n", 1234);should printHex (uppercase): 4D2.
-
Percent
%%:ft_printf("Percent: %%\n");should printPercent: %.
-
Flags
-0.and Field Width:- Left-justify:
ft_printf("Left-justify: %-10d!\n", 123);should printLeft-justify: 123 !. - Zero-padding:
ft_printf("Zero-padding: %010d!\n", 123);should printZero-padding: 0000000123!. - Precision:
ft_printf("Precision: %.5d!\n", 123);should printPrecision: 00123!.
- Left-justify:
-
Flags
# +:- Alternate form:
ft_printf("Alternate form: %#x!\n", 123);should printAlternate form: 0x7b!. - Space:
ft_printf("Space: % d!\n", 123);should printSpace: 123!. - Sign:
ft_printf("Sign: %+d!\n", 123);should printSign: +123!.
- Alternate form:
-
Handling NULL strings:
ft_printf("NULL string: %s\n", NULL);should printNULL string: (null).
-
Edge cases:
- Zero value:
ft_printf("Zero: %d %x %u\n", 0, 0, 0);should printZero: 0 0 0. - Large numbers:
ft_printf("Large number: %u\n", UINT_MAX);should print the maximum unsigned int value.
- Zero value:
By covering these test cases, you ensure that your ft_printf() implementation correctly handles all specified functionalities and edge cases.