GithubHelp home page GithubHelp logo

ft_printf's Introduction

Ft_printf

ABOUT THE PROJECT

This project has been approached with a constant pursuit of efficiency, consolidating its implementation into a single file containing only five functions. These functions have been meticulously crafted to adhere to the rigorous style standards set by school 42. The assignment involves creating a custom function similar to the printf function in the C programming language, with a focus on enhancing skills related to string manipulation, efficient handling of variable arguments, and output formatting within the context of the C language. The specified conversions are as follows:

%c Prints a single character.

%s Prints a C string.

%p Prints the memory address of a pointer.

%d Prints a decimal number (base 10).

%i Prints an integer (base 10).

%u Prints an unsigned decimal number (base 10).

%x Prints a hexadecimal number in lowercase (base 16).

%X Prints a hexadecimal number in uppercase (base 16).

%% Prints the percentage symbol.

BRIEF EXPLANATION OF MY FT_PRINTF'S FUNCTIONS

ft_write: Prints a character or a string to standard output and counts the corresponding number of printed items.

ft_convert: Performs specific conversions for the formats %d, %i, %p, %u, %x, %X. Depending on the data type associated with the format, it carries out necessary conversions to ensure that the value is handled within the bounds of its type.

ft_hexabase: Converts a number to its hexadecimal or decimal representation, depending on the specified format, and then prints the resulting representation to standard output.

ft_exec_printf: Loop that iterates over the format string, printing elements based on detected formats.

ft_printf: Main function that runs the loop.

HOW TO USE IT?

Clone the repository:

Open your terminal and run the following command to clone the repository:

git clone [email protected]:Ismaelm42/Ft_printf.git

Go into your local repository folder. The project uses a Makefile to manage the build.

make

The make command will compile the project and generate the libftprintf.a library.

Additional commands:

make re

Deletes and recompiles the project from scratch.

make clean

Removes object (.o) files generated during compilation.

make fclean

Removes object files and the library (.a).

USAGE

After compiling the library, you can use it in your projects. Make sure that your source code file includes the corresponding header (ft_printf.h). You can include it in your source code file as follows:

#include "ft_printf.h"

When compiling your program, be sure to link it to the libftprintf.a library:

gcc my_program.c libftprintf.a -o my_program

This is a very simple test that you can use and compare with the original printf function if you are starting this project:

#include "ft_printf.h"

int	main(void)
{
	char		c = 'a';
	char		str[] = "Hello World";
	int		n = 123456789;
	unsigned int	u = -123456789;
	void		*ptr = str;

	ft_printf("char = %c\n", c);
	ft_printf("string = %s\n", str);
	ft_printf("integer = %i\n", n);
	ft_printf("decimal = %d\n", n);
	ft_printf("unsigned = %u\n", u);
	ft_printf("pointer = %p\n", ptr);
	ft_printf("hexadecimal = %x\n", n);
	ft_printf("HEXADECIMAL = %X\n", n);
	ft_printf("percentage = %%\n");
	return (0);
}

The output should look something like this:

char = 		a
string = 	Hello World
integer = 	123456789
decimal = 	123456789
unsigned = 	4171510507
pointer	= 	0x7fffae04f5ab
hexadecimal = 	75bcd15
HEXADECIMAL =	75BCD15
percentage = 	%

PROGRAMMING LANGUAGE

C-logo

ft_printf's People

Contributors

ismaelm42 avatar

Stargazers

 avatar

Watchers

 avatar

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.