10000 GitHub - lsjoberg98/ft_printf: substitute for printf
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

lsjoberg98/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_printf

Score 110/100

Mandatory

100/100

Bonus

10/25


Challenge

At Hive, students are not allowed to use library functions. We can only submit wholly self-written functions (no strlen, strdup, bzero etc.). ft_printf must be formatted in the same manor as libc's printf. For example:

ft_printf("%s is %d years old\n", "Lucas", 42);
printf("%s is %d years old\n", "Lucas", 42);

Should give back:

Lucas is 42 years old
Lucas is 42 years old

The project is complicated as the number of parameters is indefinite. I use variadic arguments in this case.

ft_printf must achieve the following mandatory requirements:

  • Manage the following conversions: s, S, p, d, D, i, o, O, u, U, x, X, c & C
  • Manage %%
  • Manage the flags #, 0, -, + & space
  • Manage the minimum field-width
  • Manage the precision
  • Manage the flags hh, h, l, ll, j, & z.

The function must conform to Hive's norm.
The function cannot leak. All errors must be handled carefully. In no way can the function quit in an unexpected manner (Segmentation fault, bus error, double free, etc).
Allowed functions are write, getloacale, malloc, free, exit and the three functions of stdarg. Everything else is forbidden.


Using the project

To compile, run make. This will compile libftprintf.a. To use, include ft_printf.h (located inside includes directory) and use just like printf:

#include "ft_printf.h"

int				main(void)
{
	ft_printf("%s, %s!\n", "Hello", "world");
	return (0);
}

Then compile with a program:

gcc -Wall -Werror -Wextra main.c libftprintf.a -I includes

About

substitute for printf

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0