nanafox / printf Goto Github PK
View Code? Open in Web Editor NEWA group implementation of the printf function
A group implementation of the printf function
Here's the prototype to use
#include "main.h"
/**
* _itob - convert integer to the specified base and stores the result
* as a string
*
* @number: the number to convert
* @buffer: the string buffer to store the result
* @base: the base to convert @number to
*/
void _itob(ssize_t number, char *buffer, int base);
Your function should handle bases 2, 8, 10, and 16. The main.h
has macros for these tokens, use them.
Example: BIN
is assigned to 2, HEX
to 16
Prototypes:
int handle_decimal(const format_specifier *spec, va_list args, string_buffer *buffer);
File: handle_numbers.c
Prototype: char *_strdup(const char *s);
Your function should handle edge cases well, it should work like the standard library's strdup()
function.
It should be in the file _strdup.c
Prototype:
int handle_precision(const char *format, format_specifier *spec, string_buffer *buffer);
File: handle_precision.c
Prototypes to use
int handle_string(const format_specifier *spec, va_list args, string_buffer *buffer);
int handle_char(const format_specifier *spec, va_list args, string_buffer *buffer);
int handle_percent(const format_specifier *spec, va_list args, string_buffer *buffer);
Prototype:
int handle_pointer(const format_specifier *spec, va_list args, string_buffer *buffer);
File: handle_pointers.c
Prototypes
/* for %x */
int handle_hex_lower(const format_specifier *spec, va_list args, string_buffer *buffer);
/* for %X */
int handle_hex_upper(const format_specifier *spec, va_list args, string_buffer *buffer);
File: handle_hexadecimal.c
Prototype: size_t _strlen(const char *str);
File: _strlen.c
The prototype for this function can be found in the main.h
file.
Could you be sure to handle corner cases as well?
Here's the prototype void _reverse_str(char *buffer, size_t len);
Where buffer
is the string to reverse, and len
is the length of the string.
Please make sure that the function handles errors as well. For example, when buffer
is NULL
or len
is zero. Ultimately, please make sure your function accounts for all edge cases.
Prototype:
int handle_binary(const format_specifier *spec, va_list args, string_buffer *buffer);
File: handle_numbers.c
Prototype:
int handle_width(const char *format, format_specifier *spec, string_buffer *buffer);
File: handle_precision.c
Prototype: char *_strchr(const char *s, int c);
This function should implement logic to locate character c
in the string s
.
You return a pointer to the first occurrence of c
in s
.
This function will be used at other places to handle different situations, it should be able to work well with other functions.
Prototype:
void utob(size_t number, char *buffer, int base);
Where
number
is the number to convert,buffer
is where to store the result (the user will provide that)base
is the base to convert to. (accepted bases are 2, 8, 10, and 16)File: _utob.c
This function will work like the _itob()
, the only difference is that we are handling solely positive numbers. We will use this one when handling conversion to hex, pointer addresses, and a few more type conversions.
Please be sure to update the main.h
with this new prototype.
Work on this as fast as you can.
Thank you!
Prototype:
/* handles the %b specifier */
int handle_binary(const format_specifier *spec, va_list args, string_buffer *buffer);
/* handles the %o specifier */
int handle_octal(const format_specifier *spec, va_list args, string_buffer *buffer);
File: handle_numbers.c
To enhance the project, make sure to add the necessary header files for string and integer handling and implement any other useful changes. All function prototypes must be in the main.h
file.
create_format_specifiers.c
Prototype format_specifier *create_format_specifiers(void);
.
This function should create an array of structs to hold functions for handling format strings for valid format specifiers
format_selector.c
Prototype: int select_format_handler(const char specifier, format_specifier *spec, va_list args, string_buffer *buffer);
This function should select the appropriate handler for a format specifier
Could you please add a function to the code that performs rot13 encryption in C? The prototype that should be used is char *rot13(char *str);
. Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.