Coder Social home page Coder Social logo

printf's Introduction

The Printf Project

printf's People

Contributors

ezeisraeljohn avatar nanafox avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

ezeisraeljohn

printf's Issues

Work on the function to convert an integer to any base and return the result as string

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

Add function to duplicate a string

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

Handle precision

Prototype:

int handle_precision(const char *format, format_specifier *spec, string_buffer *buffer);

File: handle_precision.c

Handle the %p format specifier

Prototype:

int handle_pointer(const format_specifier *spec, va_list args, string_buffer *buffer);

File: handle_pointers.c

Handle the %x and %X format specifiers

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

Add a function to reverse a string

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.

Handle the %u format specifier

Prototype:

int handle_binary(const format_specifier *spec, va_list args, string_buffer *buffer);

File: handle_numbers.c

Handle width modifiers

Prototype:

int handle_width(const char *format, format_specifier *spec, string_buffer *buffer);

File: handle_precision.c

Add a function to locate a character in a string

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.

Add a function to convert an unsigned number to a string

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!

Handle the %b and %o format specifiers

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

Add the initial header files needed.

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.

Add a function to handle the selection of format handlers.

Format selectors and Accepted Format Specifiers

Files to add

  1. 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

  2. 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.