https://github.com/mewmewdevart/ft_printf
[42 Cursus] Because ft_putnbr() and ft_putstr() arenโt enough
https://github.com/mewmewdevart/ft_printf
42born2code c library makefile printf programming variadic-arguments
Last synced: 10 months ago
JSON representation
[42 Cursus] Because ft_putnbr() and ft_putstr() arenโt enough
- Host: GitHub
- URL: https://github.com/mewmewdevart/ft_printf
- Owner: mewmewdevart
- License: mit
- Created: 2022-10-28T14:51:01.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-21T18:23:18.000Z (about 3 years ago)
- Last Synced: 2023-03-10T13:06:29.536Z (almost 3 years ago)
- Topics: 42born2code, c, library, makefile, printf, programming, variadic-arguments
- Language: C
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ft_printf
Write a library that contains ft_printf(), a function that will mimic the original printf()
## ๐ก About the project
> _For the ft_printf() project of the 42 school cursus, we must recreate the famous C library printf() function. This project teaches us about variadic arguments. The printf() function sends a formatted string to the standard output (the display).
My ft_printf has to handle the following conversions: โ
> - %c Prints a single character.
> - %s Prints a string (as defined by the common C convention).
> - %p The void * pointer argument has to be printed in hexadecimal format.
> - %d Prints a decimal (base 10) number.
> - %i Prints an integer in base 10.
> - %u Prints an unsigned decimal (base 10) number.
> - %x Prints a number in hexadecimal (base 16) lowercase format.
> - %X Prints a number in hexadecimal (base 16) uppercase format.
> - %% Prints a percent sign.
## ๐ Files/
* [`libraries/`](libraries)
Calling for my libraries
- ```libft/``` my custom-made library ( [see the project here](https://github.com/mewmewdevart/libft) )
- ```ft_printf.h``` my ft_printf header to connect the functions created for this project
* [`sources/`](sources)[`ft_printf.c`](sources/ft_printf.c) My main function implementation
- ```ft_printf``` the "controller"
- ```ft_translate``` translate what happens after the % symbol
- ```ft_putchar``` write a character, of unsigned char type, to stdout (libft)
- ```ft_putnbr``` function to diplay number (converted) with "ft_putchar" function (libft)
- ```ft_putnbr_unsigned``` function to diplay number (unsigned int) with "ft_putchar" function (libft)
- ```ft_putptr``` function print the address of pointer with "ft_puthexa" function(libft)
- ```ft_puthex``` function to printf in hexadecimal format (libft)
* [`Makefile`](Makefile) My build automation between libft and ft_printf libraries
## ๐ ๏ธ Usage
### Requirements
This project requires [GNU Compiler Collection](https://gcc.gnu.org/) and [GNU Make](https://www.gnu.org/software/make/) compiler.
โ๏ธ| Make sure you have all the required tools installed on your local machine then continue with these steps.
### Instructions
**0. Download the archives**
Download the archives and go to the library directory:
```bash
# Clone the repository
$ git clone https://github.com/mewmewdevart/ft_printf
# Enter into the directory
$ cd ft_printf/
```
**1. Compiling the library**
Run the command in your terminal :
```shell
$ make
```
**2. Using it in your code**
To use the ft_printf actions in your code, simply include its header:
```c
#include "libraries/ft_printf.h"
```
And create a main with some inserts/conversions
Example ``main.c``:
```c
#include "libraries/ft_printf.h"
int main(void)
{
char *string;
string = "larissa";
ft_printf("%s ", string);
return (0);
}
```
If you try to compile your .c files with cc using "cc main.c" you will get an undefined symbol error for Libftprintf functions.
You have to tell the file which library it's using:
```shell
$ cc main.c libftprintf.a -o prog_example
```
To run the program, enter the following in the command prompt:
```shell
$ ./prog_example
```
The example I showed you will allow you to view a string of characters that will be displayed in your output terminal like this:
```shell
$ larissa
```
You can try `c`, `s`, `p`, `d`, `i`, `u`, `x`, `X` or `%` conversions!
```c
#include "libraries/ft_printf.h"
int main(void)
{
ft_printf("%d and %i is very %s", 42, 42, "cool");
return (0);
}
```
Output:
```
42 and 42 is very cool
```
## ๐ Credits
* [Acelera/Rodsmade](https://github.com/rodsmade/Projets_42_SP/)
* [ft_printf_tester/paulo-santana/](https://github.com/paulo-santana/ft_printf_tester)
* [printfTester/Tripouille](https://github.com/Tripouille/printfTester)
Developed with love ๐ by Larissa Cristina Benedito (Mewmew/Larcrist).