commit
This commit is contained in:
BIN
C_02/git/ex11/._main.c
Normal file
BIN
C_02/git/ex11/._main.c
Normal file
Binary file not shown.
40
C_02/git/ex11/ft_putstr_non_printable.c
Normal file
40
C_02/git/ex11/ft_putstr_non_printable.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_non_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/11 11:29:09 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/12 11:40:23 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// for i in {0..127}; do printf "%02x" $i; done
|
||||
void ft_putstr_non_printable(char *str)
|
||||
{
|
||||
const char *hex = "\
|
||||
000102030405060708090a0b0c0d0e0f\
|
||||
101112131415161718191a1b1c1d1e1f\
|
||||
202122232425262728292a2b2c2d2e2f\
|
||||
303132333435363738393a3b3c3d3e3f\
|
||||
404142434445464748494a4b4c4d4e4f\
|
||||
505152535455565758595a5b5c5d5e5f\
|
||||
606162636465666768696a6b6c6d6e6f\
|
||||
707172737475767778797a7b7c7d7e7f";
|
||||
|
||||
while (*str != '\0')
|
||||
{
|
||||
if (*str >= ' ' && *str != '~' + 1)
|
||||
write(1, str, 1);
|
||||
else
|
||||
{
|
||||
write(1, "\\", 1);
|
||||
write(1, hex + *str * 2, 2);
|
||||
}
|
||||
str++;
|
||||
}
|
||||
}
|
||||
32
C_02/git/ex11/main.c
Normal file
32
C_02/git/ex11/main.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/11 11:24:31 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/12 11:44:53 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void ft_putstr_non_printable(char *str);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *test = "Coucou\ntu vas bien ?";
|
||||
char str[256];
|
||||
|
||||
printf("Input [max 255]: ");
|
||||
scanf("%255[^\n]", str);
|
||||
printf("str=%s\n", str);
|
||||
ft_putstr_non_printable(str);
|
||||
printf("test=%s\n", test);
|
||||
ft_putstr_non_printable((char *)test);
|
||||
return (0);
|
||||
}
|
||||
8
C_02/git/ex11/main.sh
Executable file
8
C_02/git/ex11/main.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
||||
norminette -R CheckForbiddenSourceHeader
|
||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
||||
echo $(basename $PWD):
|
||||
./a.out
|
||||
rm -f a.out
|
||||
Reference in New Issue
Block a user