init
This commit is contained in:
41
Correction/thellego/ex11/ft_putstr_non_printable.c
Normal file
41
Correction/thellego/ex11/ft_putstr_non_printable.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_non_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thellego <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 15:54:18 by thellego #+# #+# */
|
||||
/* Updated: 2022/07/18 22:39:25 by thellego ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_printhexa(int i)
|
||||
{
|
||||
int nb;
|
||||
|
||||
nb = i / 16;
|
||||
write(1, "\\", 1);
|
||||
write(1, &"0123456789abcdef"[nb % 16], 1);
|
||||
write(1, &"0123456789abcdef"[i % 16], 1);
|
||||
}
|
||||
|
||||
void ft_putstr_non_printable(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] >= 32 && str[i] <= 126)
|
||||
write(1, &str[i], 1);
|
||||
else
|
||||
ft_printhexa(str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/*int main(void){
|
||||
ft_putstr_non_printable("Coucou\ntu vas bien ?");
|
||||
}*/
|
Reference in New Issue
Block a user