init commit
This commit is contained in:
commit
e078efd325
284 changed files with 8382 additions and 0 deletions
brainfuck
d00
ex01
ex02
ex03
ex04
ex05
ex06
ex07
ex08
ex09
ex10
ex11
d01
ex01
ex02
ex03
ex04
ex05
ex06
ex07
ex08
ex09
d02
ex00
ex01
ex02
ex03
ex04
ex06
d03
ex00
ex01
ex02
ex03
ex04
ex05
ex06
ex07
ex08
ex09
d04
ex00
ex01
ex02
ex03
ex04
ex05
ex06
d05
ex00
ex01
ex02
ex03
ex04
ex05
ex06
ex07
ex08
ex09
ex10
ex11
ex12
ex13
ex14
ex15
ex16
d06
ex00
ex01
ex02
ex03
ex04
d07
ex00
ex01
ex02
ex03
ex04
d08
ex00
ex01
ex02
ex03
ex04
d09
ex00
ex01
ex02
ex03
ex04
ex05
ex06
ex07
ex08
ex09
32
brainfuck/Makefile
Normal file
32
brainfuck/Makefile
Normal file
|
@ -0,0 +1,32 @@
|
|||
# MAkefile
|
||||
# AUTHOR: foton
|
||||
# FILE: Makefile
|
||||
# ROLE: to compile them all
|
||||
# CREATED: 2016-11-20 00:59:16
|
||||
# MODIFIED: 2016-11-20 01:14:41
|
||||
|
||||
NAME = brainfuck
|
||||
CC = clang
|
||||
FLAGS = -Wall -Werror -Wextra
|
||||
SRC = src/main.c \
|
||||
src/output.c \
|
||||
src/brainfuck.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
INC = -I inc/
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
$(CC) $(FLAGS) $(OBJ) $(INC) -o $(NAME)
|
||||
|
||||
.c.o: $(SRC)
|
||||
$(CC) $(FLAGS) $(INC) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(BIN)$(NAME)
|
||||
|
||||
re:
|
||||
fclean all
|
11
brainfuck/README
Normal file
11
brainfuck/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Text File
|
||||
# AUTHOR: foton
|
||||
# FILE: README
|
||||
# ROLE: to rule them all
|
||||
# CREATED: 2016-11-20 01:18:23
|
||||
# MODIFIED: 2016-11-20 01:20:33
|
||||
|
||||
Simple brainfuck interpreter.
|
||||
|
||||
compile: "make fclean, make" or "make re"
|
||||
test: "cat hello_world.bf | xargs ./brainfuck"
|
1
brainfuck/hello_world.bf
Normal file
1
brainfuck/hello_world.bf
Normal file
|
@ -0,0 +1 @@
|
|||
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
|
17
brainfuck/inc/brnfck.h
Normal file
17
brainfuck/inc/brnfck.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// C/C++ File
|
||||
// AUTHOR: foton
|
||||
// FILE: brnfck.h
|
||||
// ROLE: to rule them all
|
||||
// CREATED: 2016-11-20 00:52:13
|
||||
// MODIFIED: 2016-11-20 00:54:35
|
||||
|
||||
#ifndef BRNFCK_H
|
||||
# define BRNFCK_H
|
||||
|
||||
# define SIZE 30000
|
||||
|
||||
int brainfuck(char *source);
|
||||
void my_putchar(char c);
|
||||
void my_putstr(char *str);
|
||||
|
||||
#endif
|
52
brainfuck/src/brainfuck.c
Normal file
52
brainfuck/src/brainfuck.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
// C/C++ File
|
||||
// AUTHOR: foton
|
||||
// FILE: brainfuck.c
|
||||
// ROLE: to rule them all
|
||||
// CREATED: 2016-11-19 22:28:26
|
||||
// MODIFIED: 2016-11-20 01:13:18
|
||||
// TODO: nested loops
|
||||
// read user input
|
||||
// handle errors (incorrect source)
|
||||
// read from file and stdin
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "brnfck.h"
|
||||
|
||||
int brainfuck(char *source)
|
||||
{
|
||||
char *array;
|
||||
int i;
|
||||
int head;
|
||||
int start_loop;
|
||||
|
||||
i = 0;
|
||||
array = malloc(sizeof(char) * SIZE);
|
||||
while (i < SIZE)
|
||||
array[i++] = 0;
|
||||
i = 0;
|
||||
head = 0;
|
||||
start_loop = 0;
|
||||
while (source[i])
|
||||
{
|
||||
if (source[i] == '+')
|
||||
array[head]++;
|
||||
if (source[i] == '-')
|
||||
array[head]--;
|
||||
if (source[i] == '>')
|
||||
head++;
|
||||
if (source[i] == '<')
|
||||
head--;
|
||||
if (source[i] == '.')
|
||||
my_putchar(array[head]);
|
||||
if (source[i] == '[')
|
||||
start_loop = i;
|
||||
if (source[i] == ']')
|
||||
{
|
||||
if (!(array[head] == 0))
|
||||
i = start_loop - 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
free(array);
|
||||
return (0);
|
||||
}
|
23
brainfuck/src/main.c
Normal file
23
brainfuck/src/main.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
// C/C++ File
|
||||
// AUTHOR: foton
|
||||
// FILE: main.c
|
||||
// ROLE: to rule them all
|
||||
// CREATED: 2016-11-19 22:28:26
|
||||
// MODIFIED: 2016-11-20 01:15:58
|
||||
|
||||
#include "brnfck.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
my_putstr("Dude, put some source to work with!\n");
|
||||
return (0);
|
||||
}
|
||||
if (brainfuck(argv[1]) == 1)
|
||||
{
|
||||
my_putstr("Something goes wrong :(\n");
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
19
brainfuck/src/output.c
Normal file
19
brainfuck/src/output.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
// C/C++ File
|
||||
// AUTHOR: foton
|
||||
// FILE: output.c
|
||||
// ROLE: to rule them all
|
||||
// CREATED: 2016-11-19 22:28:26
|
||||
// MODIFIED: 2016-11-20 00:51:42
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void my_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
write(1, str++, 1);
|
||||
}
|
||||
|
||||
void my_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
BIN
d00/ex01/testDay00.tar
Normal file
BIN
d00/ex01/testDay00.tar
Normal file
Binary file not shown.
BIN
d00/ex02/exo2.tar
Normal file
BIN
d00/ex02/exo2.tar
Normal file
Binary file not shown.
5
d00/ex03/klist.txt
Normal file
5
d00/ex03/klist.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
Credentials cache: API:4728
|
||||
Principal: gtertysh@UNIT.UA
|
||||
|
||||
Issued Expires Principal
|
||||
Oct 26 12:13:24 2016 Oct 26 22:13:16 2016 krbtgt/UNIT.UA@UNIT.UA
|
1
d00/ex04/who_am_i.sh
Normal file
1
d00/ex04/who_am_i.sh
Normal file
|
@ -0,0 +1 @@
|
|||
ldapwhoami -Q | cut -c4- | cut -d , -f1,3-
|
1
d00/ex05/people.sh
Normal file
1
d00/ex05/people.sh
Normal file
|
@ -0,0 +1 @@
|
|||
ldapsearch -Q -LLL "uid=z*" | grep "^cn" | sort -r
|
4
d00/ex06/mobile-phone.ldif
Normal file
4
d00/ex06/mobile-phone.ldif
Normal file
|
@ -0,0 +1,4 @@
|
|||
dn: uid=gtertysh,ou=november,ou=2016,ou=people,dc=unit,dc=ua
|
||||
changetype: modify
|
||||
add: mobile
|
||||
mobile: 0930351607
|
1
d00/ex07/midLS
Normal file
1
d00/ex07/midLS
Normal file
|
@ -0,0 +1 @@
|
|||
ls -mpU
|
1
d00/ex08/z
Normal file
1
d00/ex08/z
Normal file
|
@ -0,0 +1 @@
|
|||
Z
|
11
d00/ex09/b
Normal file
11
d00/ex09/b
Normal file
|
@ -0,0 +1,11 @@
|
|||
Episode V, A NEW H0PE It is a period of civil war
|
||||
Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.
|
||||
During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the STAR DEATH, an armored space station with enough power to destroy an entire planet.
|
||||
|
||||
|
||||
Pursued by the Empire's sinister agents,
|
||||
Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie..
|
||||
|
||||
|
||||
|
||||
|
1
d00/ex10/clean
Normal file
1
d00/ex10/clean
Normal file
|
@ -0,0 +1 @@
|
|||
find . -type f \( -name '*~' -o -name '#*' -o -name '*#' \) -print -delete
|
1
d00/ex11/ft_magic
Normal file
1
d00/ex11/ft_magic
Normal file
|
@ -0,0 +1 @@
|
|||
41 string 42 42 file
|
1
d01/ex01/print_groups.sh
Executable file
1
d01/ex01/print_groups.sh
Executable file
|
@ -0,0 +1 @@
|
|||
groups $FT_USER | tr ' ' ',' | tr -d '\n'
|
1
d01/ex02/find_sh.sh
Executable file
1
d01/ex02/find_sh.sh
Executable file
|
@ -0,0 +1 @@
|
|||
find . -name "*.sh" | rev | cut -d '.' -f 2 | cut -d '/' -f 1 | rev
|
1
d01/ex03/count_files.sh
Executable file
1
d01/ex03/count_files.sh
Executable file
|
@ -0,0 +1 @@
|
|||
find . | wc -l | tr -d " "
|
1
d01/ex04/MAC.sh
Executable file
1
d01/ex04/MAC.sh
Executable file
|
@ -0,0 +1 @@
|
|||
ifconfig | tr -d "\t" | grep "^ether" | cut -d " " -f 2
|
0
d01/ex05/"?$*KwaMe*$?\"
Normal file
0
d01/ex05/"?$*KwaMe*$?\"
Normal file
1
d01/ex05/"\?$*'KwaMe'*$?\"
Normal file
1
d01/ex05/"\?$*'KwaMe'*$?\"
Normal file
|
@ -0,0 +1 @@
|
|||
42
|
1
d01/ex06/skip.sh
Executable file
1
d01/ex06/skip.sh
Executable file
|
@ -0,0 +1 @@
|
|||
ls -l | sed -n "p;n"
|
1
d01/ex07/r_dwssap.sh
Executable file
1
d01/ex07/r_dwssap.sh
Executable file
|
@ -0,0 +1 @@
|
|||
cat /etc/passwd | grep -v ^# | sed -n 'n;p' | cut -d ":" -f1 | rev | sort -r | sed -n "$FT_LINE1,$FT_LINE2 p" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/, /g' | tr "\n" "."
|
1
d01/ex08/bon.sh
Executable file
1
d01/ex08/bon.sh
Executable file
|
@ -0,0 +1 @@
|
|||
ldapsearch -Q | grep ^givenName | grep -i "bon" | wc -l | tr -d " "
|
0
d01/ex09/add_chelou.sh
Normal file
0
d01/ex09/add_chelou.sh
Normal file
25
d02/ex00/ft_print_alphabet.c
Normal file
25
d02/ex00/ft_print_alphabet.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_alphabet.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/26 17:23:25 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/27 20:23:08 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_print_alphabet(void)
|
||||
{
|
||||
char a;
|
||||
|
||||
a = 'a';
|
||||
while (a <= 'z')
|
||||
{
|
||||
ft_putchar(a);
|
||||
a = a + 1;
|
||||
}
|
||||
}
|
25
d02/ex01/ft_print_reverse_alphabet.c
Normal file
25
d02/ex01/ft_print_reverse_alphabet.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_reverse_alphabet.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/27 10:58:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/27 11:39:26 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_print_reverse_alphabet(void)
|
||||
{
|
||||
char z;
|
||||
|
||||
z = 'z';
|
||||
while (z >= 'a')
|
||||
{
|
||||
ft_putchar(z);
|
||||
z = z - 1;
|
||||
}
|
||||
}
|
25
d02/ex02/ft_print_numbers.c
Normal file
25
d02/ex02/ft_print_numbers.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_numbers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/27 10:59:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/27 11:40:34 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_print_numbers(void)
|
||||
{
|
||||
char z;
|
||||
|
||||
z = '0';
|
||||
while (z <= '9')
|
||||
{
|
||||
ft_putchar(z);
|
||||
z = z + 1;
|
||||
}
|
||||
}
|
25
d02/ex03/ft_is_negative.c
Normal file
25
d02/ex03/ft_is_negative.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_negative.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/27 10:59:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/27 20:23:36 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_is_negative(int n)
|
||||
{
|
||||
if (n >= 0)
|
||||
{
|
||||
ft_putchar('P');
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putchar('N');
|
||||
}
|
||||
}
|
49
d02/ex04/ft_print_comb.c
Normal file
49
d02/ex04/ft_print_comb.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_comb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/27 10:26:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/27 11:46:09 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putnumb(char a, char b, char c)
|
||||
{
|
||||
ft_putchar(a);
|
||||
ft_putchar(b);
|
||||
ft_putchar(c);
|
||||
if (!(a == '7' && b == '8' && c == '9'))
|
||||
{
|
||||
ft_putchar(',');
|
||||
ft_putchar(' ');
|
||||
}
|
||||
}
|
||||
|
||||
void ft_print_comb(void)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
|
||||
a = 0;
|
||||
while (a <= 7)
|
||||
{
|
||||
b = a + 1;
|
||||
while (b <= 8)
|
||||
{
|
||||
c = b + 1;
|
||||
while (c <= 9)
|
||||
{
|
||||
ft_putnumb(a + '0', b + '0', c + '0');
|
||||
c++;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
}
|
38
d02/ex06/ft_putnbr.c
Normal file
38
d02/ex06/ft_putnbr.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/27 17:17:51 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/27 21:46:40 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_printnbr(int nb)
|
||||
{
|
||||
int temp;
|
||||
long div;
|
||||
|
||||
temp = nb;
|
||||
div = 1;
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar('-');
|
||||
}
|
||||
while (temp)
|
||||
{
|
||||
temp = temp / 10;
|
||||
div = div * 10;
|
||||
}
|
||||
while (div > 1)
|
||||
{
|
||||
div = div / 10;
|
||||
ft_putchar(nb / div + '0');
|
||||
nb = nb % div;
|
||||
}
|
||||
}
|
16
d03/ex00/ft_ft.c
Normal file
16
d03/ex00/ft_ft.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft-ft.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/27 12:09:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/03 12:29:49 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_ft(int *nbr)
|
||||
{
|
||||
*nbr = 42;
|
||||
}
|
16
d03/ex01/ft_ultimate_ft.c
Normal file
16
d03/ex01/ft_ultimate_ft.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_ft.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 09:49:54 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 19:17:24 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_ultimate_ft(int *********nbr)
|
||||
{
|
||||
*********nbr = 42;
|
||||
}
|
20
d03/ex02/ft_swap.c
Normal file
20
d03/ex02/ft_swap.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_swap(int *a, int *b)
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = *a;
|
||||
*a = *b;
|
||||
*b = temp;
|
||||
}
|
BIN
d03/ex03/ft_div_mod
Executable file
BIN
d03/ex03/ft_div_mod
Executable file
Binary file not shown.
17
d03/ex03/ft_div_mod.c
Normal file
17
d03/ex03/ft_div_mod.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_div_mod.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 10:16:49 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 10:28:23 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_div_mod(int a, int b, int *div, int *mod)
|
||||
{
|
||||
*div = a / b;
|
||||
*mod = a % b;
|
||||
}
|
20
d03/ex04/ft_ultimate_div_mod.c
Normal file
20
d03/ex04/ft_ultimate_div_mod.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_div_mode.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 10:30:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 21:17:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_ultimate_div_mod(int *a, int *b)
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = *a / *b;
|
||||
*b = *a % *b;
|
||||
*a = temp;
|
||||
}
|
22
d03/ex05/ft_putstr.c
Normal file
22
d03/ex05/ft_putstr.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 10:45:38 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 11:09:43 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str != '\0')
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
24
d03/ex06/ft_strlen.c
Normal file
24
d03/ex06/ft_strlen.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
while (*str != '\0')
|
||||
{
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
return (count);
|
||||
}
|
37
d03/ex07/ft_strrev.c
Normal file
37
d03/ex07/ft_strrev.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrev.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 11:30:14 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 21:01:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strrev(char *str)
|
||||
{
|
||||
int count;
|
||||
int char_numb;
|
||||
char *temp_ptr;
|
||||
char temp;
|
||||
|
||||
count = 0;
|
||||
char_numb = 0;
|
||||
temp_ptr = str;
|
||||
while (*temp_ptr != '\0')
|
||||
{
|
||||
char_numb++;
|
||||
temp_ptr++;
|
||||
}
|
||||
while (char_numb > count)
|
||||
{
|
||||
temp = *(str + char_numb - 1);
|
||||
*(str + char_numb - 1) = *(str + count);
|
||||
*(str + count) = temp;
|
||||
count++;
|
||||
char_numb--;
|
||||
}
|
||||
return (str);
|
||||
}
|
24
d03/ex08/ft_atoi.c
Normal file
24
d03/ex08/ft_atoi.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 12:27:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 21:02:24 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(char *p)
|
||||
{
|
||||
int numb;
|
||||
|
||||
numb = 0;
|
||||
while (*p != '\0')
|
||||
{
|
||||
numb = numb * 10 + (*p) - '0';
|
||||
p++;
|
||||
}
|
||||
return (numb);
|
||||
}
|
40
d03/ex09/ft_sort_integer_table.c
Normal file
40
d03/ex09/ft_sort_integer_table.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sort_integer_table.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 10:16:57 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/29 12:03:44 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_sort_integer_table(int *tab, int size)
|
||||
{
|
||||
int temp;
|
||||
int i;
|
||||
int a;
|
||||
int swapped;
|
||||
|
||||
i = 0;
|
||||
a = 0;
|
||||
while(i < size - 1)
|
||||
{
|
||||
swapped = 0;
|
||||
while(a < size - 1 - i)
|
||||
{
|
||||
if (*(tab + a) > *(tab + a + 1))
|
||||
{
|
||||
temp = *(tab + a);
|
||||
*(tab + a) = *(tab + a + 1);
|
||||
*(tab + a + 1) = temp;
|
||||
swapped = 1;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
i++;
|
||||
if(!swapped)
|
||||
break;
|
||||
}
|
||||
}
|
31
d04/ex00/ft_iterative_factorial.c
Normal file
31
d04/ex00/ft_iterative_factorial.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iterative_factorial.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 15:38:54 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 15:38:59 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_iterative_factorial(int nb)
|
||||
{
|
||||
int fac;
|
||||
|
||||
fac = 1;
|
||||
if (nb > 12 || nb < 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (nb > 0)
|
||||
{
|
||||
fac *= nb;
|
||||
nb--;
|
||||
}
|
||||
}
|
||||
return (fac);
|
||||
}
|
24
d04/ex01/ft_recursive_factorial.c
Normal file
24
d04/ex01/ft_recursive_factorial.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_recursive_factorial.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 12:29:58 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/29 14:34:23 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_recursive_factorial(int nb)
|
||||
{
|
||||
if (nb < 0 || nb > 12)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
else if (nb >= 1 && nb <= 12)
|
||||
{
|
||||
return (nb *= ft_recursive_factorial(nb - 1));
|
||||
}
|
||||
return (1);
|
||||
}
|
32
d04/ex02/ft_iterative_power.c
Normal file
32
d04/ex02/ft_iterative_power.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iterative_power.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 14:35:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/29 14:56:28 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_iterative_power(int nb, int power)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (power < 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
else if (power == 0)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
result = nb;
|
||||
while (power > 1)
|
||||
{
|
||||
result *= nb;
|
||||
power--;
|
||||
}
|
||||
return (result);
|
||||
}
|
25
d04/ex03/ft_recursive_power.c
Normal file
25
d04/ex03/ft_recursive_power.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_recursive_power.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 14:57:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 15:46:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_recursive_power(int nb, int power)
|
||||
{
|
||||
if (power < 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
else if (power == 0)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
nb = ft_recursive_power(nb, power - 1) * nb;
|
||||
return (nb);
|
||||
}
|
23
d04/ex04/ft_fibonacci.c
Normal file
23
d04/ex04/ft_fibonacci.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_fibonacci.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 15:51:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/29 17:46:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_fibonacci(int index)
|
||||
{
|
||||
if (index < 0)
|
||||
return (-1);
|
||||
else if (index == 0)
|
||||
return (0);
|
||||
else if (index == 1)
|
||||
return (1);
|
||||
else
|
||||
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
|
||||
}
|
24
d04/ex05/ft_sqrt.c
Normal file
24
d04/ex05/ft_sqrt.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sqrt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 17:56:37 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/29 21:53:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_sqrt(int numb)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i * i < nb)
|
||||
i++;
|
||||
if (i * i == nb)
|
||||
return (i);
|
||||
else
|
||||
return (0);
|
||||
}
|
32
d04/ex06/ft_is_prime.c
Normal file
32
d04/ex06/ft_is_prime.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_prime.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/29 20:00:31 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/29 22:06:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_prime(int nb)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 2;
|
||||
if (nb < 0)
|
||||
return (0);
|
||||
else if (nb < 3)
|
||||
return (0);
|
||||
else
|
||||
{
|
||||
while (i < nb / 2)
|
||||
{
|
||||
if (nb % i == 0)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
}
|
22
d05/ex00/ft_putstr.c
Normal file
22
d05/ex00/ft_putstr.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str != '\0')
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
58
d05/ex01/ft_putnbr.c
Normal file
58
d05/ex01/ft_putnbr.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putnbr_print(int nb, long div, int exeption)
|
||||
{
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar('-');
|
||||
}
|
||||
if (div == 1)
|
||||
ft_putchar('0');
|
||||
else
|
||||
{
|
||||
while (div > 1)
|
||||
{
|
||||
div = div / 10;
|
||||
ft_putchar(nb / div + '0');
|
||||
nb = nb % div;
|
||||
}
|
||||
}
|
||||
if (exeption)
|
||||
ft_putchar('8');
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
int temp;
|
||||
long div;
|
||||
int exeption;
|
||||
|
||||
div = 1;
|
||||
exeption = 0;
|
||||
temp = nb;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
nb = nb / 10;
|
||||
temp = temp / 10;
|
||||
exeption = 1;
|
||||
}
|
||||
while (temp)
|
||||
{
|
||||
temp = temp / 10;
|
||||
div = div * 10;
|
||||
}
|
||||
ft_putnbr_print(nb, div, exeption);
|
||||
}
|
36
d05/ex02/ft_atoi.c
Normal file
36
d05/ex02/ft_atoi.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 16:43:18 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int numb;
|
||||
int is_negative;
|
||||
|
||||
numb = 0;
|
||||
while (*str < 33)
|
||||
str++;
|
||||
if (*str == '-')
|
||||
{
|
||||
is_negative = 1;
|
||||
str++;
|
||||
}
|
||||
if (*str == '+')
|
||||
str++;
|
||||
while (*str >= '0' && *str <= '9' && *str != '\0')
|
||||
{
|
||||
numb = numb * 10 + *str - '0';
|
||||
str++;
|
||||
}
|
||||
if (is_negative)
|
||||
return (-numb);
|
||||
return (numb);
|
||||
}
|
26
d05/ex03/ft_strcpy.c
Normal file
26
d05/ex03/ft_strcpy.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcpy(char *dest, char *src)
|
||||
{
|
||||
char *start;
|
||||
|
||||
start = dest;
|
||||
while (*src != '\0')
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return (start);
|
||||
}
|
29
d05/ex04/ft_strncpy.c
Normal file
29
d05/ex04/ft_strncpy.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
char *start;
|
||||
unsigned int i;
|
||||
|
||||
start = dest;
|
||||
i = 0;
|
||||
while (i < n && *src)
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
i++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return (start);
|
||||
}
|
33
d05/ex05/ft_strstr.c
Normal file
33
d05/ex05/ft_strstr.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strstr(char *str, char *to_find)
|
||||
{
|
||||
char *start;
|
||||
char *find;
|
||||
|
||||
find = to_find;
|
||||
while (*str != '\0')
|
||||
{
|
||||
start = str;
|
||||
find = to_find;
|
||||
while (*str != '\0' && *find != '\0' && *str == *find)
|
||||
{
|
||||
str++;
|
||||
find++;
|
||||
}
|
||||
if (*find == '\0')
|
||||
return (start);
|
||||
str++;
|
||||
}
|
||||
return (0);
|
||||
}
|
23
d05/ex06/ft_strcmp.c
Normal file
23
d05/ex06/ft_strcmp.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (*s1 == '\0')
|
||||
return (0);
|
||||
return (*s1 - *s2);
|
||||
}
|
26
d05/ex07/ft_strncmp.c
Normal file
26
d05/ex07/ft_strncmp.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strncmp(char *s1, char *s2, unsigned int n)
|
||||
{
|
||||
while (*s1 && *s1 == *s2 && n > 0)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
n--;
|
||||
}
|
||||
if (n == 0)
|
||||
return (0);
|
||||
else
|
||||
return (*s1 - *s2);
|
||||
return (0);
|
||||
}
|
28
d05/ex08/ft_strupcase.c
Normal file
28
d05/ex08/ft_strupcase.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_struocase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strupcase(char *str)
|
||||
{
|
||||
char *counter;
|
||||
|
||||
counter = str;
|
||||
while (*counter)
|
||||
{
|
||||
if (*counter >= 'a' && *counter <= 'z')
|
||||
{
|
||||
*counter -= 32;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
*counter = '\0';
|
||||
return (str);
|
||||
}
|
28
d05/ex09/ft_strlowcase.c
Normal file
28
d05/ex09/ft_strlowcase.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlowcase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strlowcase(char *str)
|
||||
{
|
||||
char *counter;
|
||||
|
||||
counter = str;
|
||||
while (*counter)
|
||||
{
|
||||
if (*counter >= 'A' && *counter <= 'Z')
|
||||
{
|
||||
*counter += 32;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
*counter = '\0';
|
||||
return (str);
|
||||
}
|
46
d05/ex10/ft_strcapitalize.c
Normal file
46
d05/ex10/ft_strcapitalize.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcapitalize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/02 16:19:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void to_lowercase(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (*str >= 'A' && *str <= 'B')
|
||||
{
|
||||
*str += 32;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
char *ft_strcapitalize(char *str)
|
||||
{
|
||||
char *begin;
|
||||
|
||||
begin = str;
|
||||
to_lowercase(str);
|
||||
while (*str)
|
||||
{
|
||||
if (*str >= 'a' && *str <= 'z')
|
||||
{
|
||||
if (*(str - 1) >= 'z')
|
||||
*str -= 32;
|
||||
if (*(str - 1) <= 'A')
|
||||
*str -= 32;
|
||||
if (*(str - 1) >= '0' && *(str - 1) <= '9')
|
||||
*str += 32;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
*str = '\0';
|
||||
return (begin);
|
||||
}
|
24
d05/ex11/ft_str_is_alpha.c
Normal file
24
d05/ex11/ft_str_is_alpha.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_alpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_alpha(char *str)
|
||||
{
|
||||
if (!*str)
|
||||
return (1);
|
||||
while (*str)
|
||||
{
|
||||
if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z')))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
24
d05/ex12/ft_str_is_numeric.c
Normal file
24
d05/ex12/ft_str_is_numeric.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_numeric.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_numeric(char *str)
|
||||
{
|
||||
if (!*str)
|
||||
return (1);
|
||||
while (*str)
|
||||
{
|
||||
if (!(*str >= '0' && *str <= '9'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
24
d05/ex13/ft_str_is_lowercase.c
Normal file
24
d05/ex13/ft_str_is_lowercase.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_lowercase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_lowercase(char *str)
|
||||
{
|
||||
if (!*str)
|
||||
return (1);
|
||||
while (*str)
|
||||
{
|
||||
if (!(*str >= 'a' && *str <= 'z'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
24
d05/ex14/ft_str_is_uppercase.c
Normal file
24
d05/ex14/ft_str_is_uppercase.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_uppercase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_uppercase(char *str)
|
||||
{
|
||||
if (!*str)
|
||||
return (1);
|
||||
while (*str)
|
||||
{
|
||||
if (!(*str >= 'A' && *str <= 'Z'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
24
d05/ex15/ft_str_is_printable.c
Normal file
24
d05/ex15/ft_str_is_printable.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_printable(char *str)
|
||||
{
|
||||
if (!*str)
|
||||
return (1);
|
||||
while (*str)
|
||||
{
|
||||
if (!(*str >= 32 && *str <= 127))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
30
d05/ex16/ft_strcat.c
Normal file
30
d05/ex16/ft_strcat.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
char *begin;
|
||||
|
||||
begin = dest;
|
||||
while (*dest)
|
||||
{
|
||||
dest++;
|
||||
}
|
||||
while (*src)
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return (begin);
|
||||
}
|
19
d06/ex00/ft_putchar.c
Normal file
19
d06/ex00/ft_putchar.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
return (0);
|
||||
}
|
22
d06/ex00/ft_putstr.c
Normal file
22
d06/ex00/ft_putstr.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str != '\0')
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
23
d06/ex00/ft_strcmp.c
Normal file
23
d06/ex00/ft_strcmp.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (*s1 == '\0')
|
||||
return (0);
|
||||
return (*s1 - *s2);
|
||||
}
|
24
d06/ex00/ft_strlen.c
Normal file
24
d06/ex00/ft_strlen.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
while (*str != '\0')
|
||||
{
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
return (count);
|
||||
}
|
20
d06/ex00/ft_swap.c
Normal file
20
d06/ex00/ft_swap.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_swap(int *a, int *b)
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = *a;
|
||||
*a = *b;
|
||||
*b = temp;
|
||||
}
|
15
d06/ex00/libft_creator.sh
Executable file
15
d06/ex00/libft_creator.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# libft_creator.sh :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/11/02 12:08:36 by gtertysh #+# #+# #
|
||||
# Updated: 2016/11/02 19:05:47 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
gcc -c ./*.c
|
||||
ar cr libft.a ./*.o
|
||||
rm ./*.o
|
30
d06/ex01/ft_print_program_name.c
Normal file
30
d06/ex01/ft_print_program_name.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_program_name.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 12:58:06 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/02 19:06:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
argc = -argc;
|
||||
ft_putstr(argv[0]);
|
||||
ft_putchar('\n');
|
||||
return (0);
|
||||
}
|
36
d06/ex02/ft_print_params.c
Normal file
36
d06/ex02/ft_print_params.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 15:59:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/02 19:07:16 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
while (i < argc)
|
||||
{
|
||||
ft_putstr(argv[i]);
|
||||
ft_putchar('\n');
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
32
d06/ex03/ft_rev_params.c
Normal file
32
d06/ex03/ft_rev_params.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_rev_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 16:16:06 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/02 19:08:19 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
while (argc-- > 1)
|
||||
{
|
||||
ft_putstr(argv[argc]);
|
||||
ft_putchar('\n');
|
||||
}
|
||||
return (0);
|
||||
}
|
74
d06/ex04/ft_sort_params.c
Normal file
74
d06/ex04/ft_sort_params.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sort_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 16:33:17 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/02 19:02:25 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_putchar(char c);
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
ft_putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void print_argv(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
while (i < argc)
|
||||
{
|
||||
ft_putstr(argv[i]);
|
||||
ft_putchar('\n');
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int cmp(char *s1, char *s2)
|
||||
{
|
||||
while (*s1 && s2 && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (!*s1)
|
||||
return (0);
|
||||
return (*s1 - *s2);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *temp;
|
||||
|
||||
i = 1;
|
||||
j = 1;
|
||||
while (i < argc)
|
||||
{
|
||||
j = 1;
|
||||
while (j < argc - 1)
|
||||
{
|
||||
if (cmp(argv[j], argv[j + 1]) > 0)
|
||||
{
|
||||
temp = argv[j];
|
||||
argv[j] = argv[j + 1];
|
||||
argv[j + 1] = temp;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
print_argv(argc, argv);
|
||||
return (0);
|
||||
}
|
38
d07/ex00/ft_strdup.c
Normal file
38
d07/ex00/ft_strdup.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 20:38:00 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 02:41:29 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strdup(char *src)
|
||||
{
|
||||
int size;
|
||||
int i;
|
||||
char *new_str;
|
||||
char *begin;
|
||||
|
||||
begin = src;
|
||||
size = 0;
|
||||
while (*src != '\0')
|
||||
{
|
||||
src++;
|
||||
size++;
|
||||
}
|
||||
new_str = (char*)malloc(sizeof(*new_str) * (size + 1));
|
||||
i = 0;
|
||||
while (i <= size)
|
||||
{
|
||||
new_str[i] = begin[i];
|
||||
i++;
|
||||
}
|
||||
new_str[i] = '\0';
|
||||
return (new_str);
|
||||
}
|
30
d07/ex01/ft_range.c
Normal file
30
d07/ex01/ft_range.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 10:45:07 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/03 18:58:22 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_range(int min, int max)
|
||||
{
|
||||
int *array;
|
||||
int i;
|
||||
|
||||
if (min >= max)
|
||||
return (0);
|
||||
array = (int*)malloc(sizeof(int*) * (max - min));
|
||||
i = 0;
|
||||
while (i < max - min)
|
||||
{
|
||||
array[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
return (array);
|
||||
}
|
34
d07/ex02/ft_ultimate_range.c
Normal file
34
d07/ex02/ft_ultimate_range.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 11:21:09 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/03 21:53:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
int i;
|
||||
int *new_array;
|
||||
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
*range = 0;
|
||||
return (0);
|
||||
}
|
||||
new_array = (int*)malloc(sizeof(int) * (max - min));
|
||||
while (i < max - min)
|
||||
{
|
||||
new_array[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
*range = new_array;
|
||||
return (max - min);
|
||||
}
|
71
d07/ex03/ft_concat_params.c
Normal file
71
d07/ex03/ft_concat_params.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_concat_params.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 15:34:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/03 19:20:40 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int count_chars(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int chars;
|
||||
|
||||
i = 1;
|
||||
j = 0;
|
||||
chars = 0;
|
||||
while (i < argc)
|
||||
{
|
||||
j = 0;
|
||||
while (argv[i][j])
|
||||
{
|
||||
j++;
|
||||
chars++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (chars);
|
||||
}
|
||||
|
||||
void fill_string(int argc, char **argv, char *concat)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int c;
|
||||
|
||||
i = 1;
|
||||
j = 0;
|
||||
c = 0;
|
||||
while (i < argc)
|
||||
{
|
||||
j = 0;
|
||||
while (argv[i][j] != '\0')
|
||||
{
|
||||
concat[c] = argv[i][j];
|
||||
j++;
|
||||
c++;
|
||||
}
|
||||
concat[c] = '\n';
|
||||
c++;
|
||||
i++;
|
||||
}
|
||||
concat[--c] = '\0';
|
||||
}
|
||||
|
||||
char *ft_concat_params(int argc, char **argv)
|
||||
{
|
||||
char *concat;
|
||||
int chars;
|
||||
|
||||
chars = count_chars(argc, argv);
|
||||
concat = (char*)malloc(sizeof(char) * (chars + argc));
|
||||
fill_string(argc, argv, concat);
|
||||
return (concat);
|
||||
}
|
91
d07/ex04/ft_split_whitespaces.c
Normal file
91
d07/ex04/ft_split_whitespaces.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split_whitespaces.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/08 12:01:19 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char **ft_split_whitespaces(char *str)
|
||||
{
|
||||
char **table;
|
||||
char *str_begin;
|
||||
int words;
|
||||
int word_exist;
|
||||
int chars_in_word;
|
||||
int word_position;
|
||||
int char_position;
|
||||
|
||||
// count words in string
|
||||
str_begin = str;
|
||||
words = 0;
|
||||
while (*str)
|
||||
{
|
||||
while (*str == ' ' || *str == '\t' || *str == '\n')
|
||||
str++;
|
||||
word_exist = 0;
|
||||
while (*str != ' ' && *str != '\t' && *str != '\n' && *str)
|
||||
{
|
||||
str++;
|
||||
word_exist = 1;
|
||||
}
|
||||
if (word_exist)
|
||||
words++;
|
||||
}
|
||||
|
||||
// allocate memory for word pointers
|
||||
table = (char **)malloc(sizeof(char *) * (words + 1));
|
||||
|
||||
// count chars in word, allocate memory for current word
|
||||
// and fill allocated memory
|
||||
str = str_begin;
|
||||
word_position = 0;
|
||||
while (*str)
|
||||
{
|
||||
while (*str == ' ' || *str == '\t' || *str == '\n')
|
||||
str++;
|
||||
chars_in_word = 0;
|
||||
while (*str != ' ' && *str != '\t' && *str != '\n' && *str)
|
||||
{
|
||||
str++;
|
||||
chars_in_word++;
|
||||
}
|
||||
table[word_position] = (char *)malloc(sizeof(char) * (chars_in_word + 1));
|
||||
if (!chars_in_word)
|
||||
break;
|
||||
char_position = 0;
|
||||
while (chars_in_word)
|
||||
{
|
||||
table[word_position][char_position] = *(str - chars_in_word);
|
||||
chars_in_word--;
|
||||
char_position++;
|
||||
}
|
||||
table[word_position][char_position] = '\0';
|
||||
word_position++;
|
||||
}
|
||||
printf("%d\n", word_position);
|
||||
table[word_position] = 0;
|
||||
return (table);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char **a;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
//a = ft_split_whitespaces(argv[1]);
|
||||
a = ft_split_whitespaces("a1 234 ");
|
||||
while (a[i])
|
||||
{
|
||||
printf("%s\n", a[i++]);
|
||||
}
|
||||
return(0);
|
||||
}
|
74
d08/ex00/ft_split_whitespaces.c
Normal file
74
d08/ex00/ft_split_whitespaces.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split_whitespaces.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/06 17:47:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char **ft_split_whitespaces(char *str)
|
||||
{
|
||||
char **table;
|
||||
char *str_begin;
|
||||
int words;
|
||||
int word_exist;
|
||||
int chars_in_word;
|
||||
int word_position;
|
||||
|
||||
// count words in string
|
||||
str_begin = str;
|
||||
words = 0;
|
||||
while (*str)
|
||||
{
|
||||
while (*str == ' ' || *str == '\t' || *str == '\n')
|
||||
str++;
|
||||
word_exist = 0;
|
||||
while (*str != ' ' && *str != '\t' && *str != '\n' && *str)
|
||||
{
|
||||
str++;
|
||||
word_exist = 1;
|
||||
}
|
||||
if (word_exist)
|
||||
words++;
|
||||
}
|
||||
|
||||
// allocate memory for word pointers
|
||||
table = (char **)malloc(sizeof(char *) * (words + 1));
|
||||
|
||||
// count chars in word, allocate memory for current word
|
||||
// and fill allocated memory
|
||||
str = str_begin;
|
||||
while (*str)
|
||||
{
|
||||
word_position = 0;
|
||||
while (*str == ' ' || *str == '\t' || *str == '\n')
|
||||
str++;
|
||||
chars_in_word = 0;
|
||||
while (*str != ' ' && *str != '\t' && *str != '\n' && *str)
|
||||
{
|
||||
str++;
|
||||
chars_in_word++;
|
||||
}
|
||||
table[word_position] = (char *)malloc(sizeof(char) * (chars_in_word + 1));
|
||||
while(chars_in_word)
|
||||
{}
|
||||
printf("%d\n", chars_in_word);
|
||||
}
|
||||
printf("%d\n", words);
|
||||
return (table);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char **a;
|
||||
|
||||
a = ft_split_whitespaces(" asfa asfa saf af ");
|
||||
return(0);
|
||||
}
|
104
d08/ex00/ft_split_whitespaces_partialy_working.c
Normal file
104
d08/ex00/ft_split_whitespaces_partialy_working.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split_whitespaces.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/06 13:40:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void table_mem(char *string, char ***table)
|
||||
{
|
||||
int word_exist;
|
||||
int words;
|
||||
|
||||
words = 0;
|
||||
while (*string)
|
||||
{
|
||||
while (*string == ' ' || *string == '\t' || *string == '\n')
|
||||
string++;
|
||||
word_exist = 0;
|
||||
while (*string != ' ' && *string != '\t' && *string != '\n' && *string)
|
||||
{
|
||||
string++;
|
||||
word_exist = 1;
|
||||
}
|
||||
if (word_exist)
|
||||
words++;
|
||||
}
|
||||
*table = (char **)malloc(sizeof(char *) * (words + 1));
|
||||
}
|
||||
|
||||
int word_mem(char **table, int word_index, int char_in_word)
|
||||
{
|
||||
table[word_index] = (char *)malloc(sizeof(char) * (char_in_word + 1));
|
||||
if (char_in_word != 0)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
table[word_index] = 0;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
int count_chars(char **begin, char **word_begin)
|
||||
{
|
||||
int char_in_word;
|
||||
|
||||
while (**begin == ' ' || **begin == '\t' || **begin == '\n')
|
||||
(*begin)++;
|
||||
char_in_word = 0;
|
||||
*word_begin = *begin;
|
||||
while (**begin != ' ' && **begin != '\t' && **begin != '\n' && **begin)
|
||||
{
|
||||
(*begin)++;
|
||||
char_in_word++;
|
||||
}
|
||||
return (char_in_word);
|
||||
}
|
||||
|
||||
char **ft_split_whitespaces(char *str)
|
||||
{
|
||||
char **table;
|
||||
int char_in_word;
|
||||
int word_index;
|
||||
int char_index;
|
||||
char *word_begin;
|
||||
|
||||
word_index = 0;
|
||||
char_index = 0;
|
||||
table_mem(str, &table);
|
||||
while (*str)
|
||||
{
|
||||
char_in_word = count_chars(&str, &word_begin);
|
||||
word_mem(table, word_index, char_in_word);
|
||||
char_index = 0;
|
||||
while (char_in_word--)
|
||||
{
|
||||
table[word_index][char_index++] = *word_begin;
|
||||
word_begin++;
|
||||
}
|
||||
table[word_index][char_index] = '\0';
|
||||
word_index++;
|
||||
}
|
||||
return (table);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char **a;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
a = ft_split_whitespaces(" asfa asfa saf af ");
|
||||
printf("%s\n", a[2]);
|
||||
return(0);
|
||||
}
|
38
d08/ex01/ft.h
Normal file
38
d08/ex01/ft.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/05 22:38:32 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_H
|
||||
# define FT_H
|
||||
|
||||
int ft_putchar(char c);
|
||||
void ft_swap(int *a, int *b);
|
||||
char *ft_strupcase(char *str);
|
||||
char *ft_strstr(char *str, char *to_find);
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n);
|
||||
int ft_strncmp(char *s1, char *s2, unsigned int n);
|
||||
char *ft_strlowcase(char *str);
|
||||
int ft_strlen(char *str);
|
||||
char *ft_strcpy(char *dest, char *src);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
char *ft_strcat(char *dest, char *src);
|
||||
char *ft_strcapitalize(char *str);
|
||||
void to_lowercase(char *str);
|
||||
int ft_str_is_uppercase(char *str);
|
||||
int ft_str_is_printable(char *str);
|
||||
int ft_str_is_numeric(char *str);
|
||||
int ft_str_is_lowercase(char *str);
|
||||
int ft_str_is_alpha(char *str);
|
||||
void ft_putstr(char *str);
|
||||
void ft_putnbr(int nb);
|
||||
int ft_atoi(char *str);
|
||||
|
||||
#endif
|
26
d08/ex02/ft_boolean.h
Normal file
26
d08/ex02/ft_boolean.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_boolean.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 22:04:48 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/05 22:38:43 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_BOOLEAN_H
|
||||
# define FT_BOOLEAN_H
|
||||
|
||||
# include <unistd.h>
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
# define SUCCESS 0
|
||||
# define EVEN_MSG "I have an even number of arguments.\n"
|
||||
# define ODD_MSG "I have an odd number of arguments.\n"
|
||||
# define EVEN(x) (!(x % 2))
|
||||
|
||||
typedef int t_bool;
|
||||
|
||||
#endif
|
18
d08/ex03/ft_abs.h
Normal file
18
d08/ex03/ft_abs.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_abs.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 22:32:24 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/05 22:34:24 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_ABS_H
|
||||
# define FT_ABS_H
|
||||
|
||||
# define ABS(Value) ((Value < 0) ? -Value : Value)
|
||||
|
||||
#endif
|
22
d08/ex04/ft_point.h
Normal file
22
d08/ex04/ft_point.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_point.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 22:35:46 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/05 22:38:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_POINT_H
|
||||
# define FT_POINT_H
|
||||
|
||||
typedef struct s_point
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} t_point;
|
||||
|
||||
#endif
|
18
d09/ex00/ft_generic.c
Normal file
18
d09/ex00/ft_generic.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_generic.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:52:10 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 02:17:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_generic(void)
|
||||
{
|
||||
write(1, "Tu tu tu tu ; Tu tu tu tu\n", 26);
|
||||
}
|
32
d09/ex01/ft_takes_place.c
Normal file
32
d09/ex01/ft_takes_place.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_takes_place.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 19:21:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 02:01:32 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void ft_take_place(int hour)
|
||||
{
|
||||
char *a;
|
||||
|
||||
a = "THE FOLLOWING TAKES PLACE BETWEEN ";
|
||||
if (hour == 0)
|
||||
printf("%s12.00 A.M. AND 1.00 A.M\n", a);
|
||||
else if (hour == 23)
|
||||
printf("%s11.00 P.M. AND 12.00 A.M\n", a);
|
||||
else if (hour == 11)
|
||||
printf("%s11.00 A.M. AND 12.00 P.M\n", a);
|
||||
else if (hour == 12)
|
||||
printf("%s12.00 P.M. AND 1.00 P.M\n", a);
|
||||
else if (hour > 12)
|
||||
printf("%s%d.00 P.M. AND %d.00 P.M\n", a, hour - 12, hour - 12 + 1);
|
||||
else
|
||||
printf("%s%d.00 A.M. AND %d.00 A.M\n", a, hour, hour + 1);
|
||||
}
|
13
d09/ex02/find_nicolas_bomber.sh
Executable file
13
d09/ex02/find_nicolas_bomber.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# find_nicolas_bomber.sh :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/11/03 20:27:43 by gtertysh #+# #+# #
|
||||
# Updated: 2016/11/04 02:01:26 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
cat $1 | grep -i ^nicolas | cut -d $'\t' -f2- | grep -i ^bomber | cut -d$'\t' -f2 | grep [0-9]
|
14
d09/ex03/defuse.sh
Executable file
14
d09/ex03/defuse.sh
Executable file
|
@ -0,0 +1,14 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# defuse.sh :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/11/03 21:41:01 by gtertysh #+# #+# #
|
||||
# Updated: 2016/11/04 02:01:19 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LAST_ACCESS_TIME=$(stat -f %a bomb.txt)
|
||||
echo "$LAST_ACCESS_TIME - 1" | bc
|
27
d09/ex04/ft_rot42.c
Normal file
27
d09/ex04/ft_rot42.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_rot42.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 21:58:10 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 02:01:11 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_rot42(char *str)
|
||||
{
|
||||
char *begin;
|
||||
|
||||
begin = str;
|
||||
while (*str)
|
||||
{
|
||||
if (*str >= 'A' && *str <= 'Z')
|
||||
*str = (*str - 65 + 42) % 26 + 65;
|
||||
else if (*str >= 'a' && *str <= 'z')
|
||||
*str = (*str - 97 + 42) % 26 + 97;
|
||||
str++;
|
||||
}
|
||||
return (begin);
|
||||
}
|
39
d09/ex05/ft_button.c
Normal file
39
d09/ex05/ft_button.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_button.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 22:46:07 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/03 23:15:53 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_button(int i, int j, int k)
|
||||
{
|
||||
int temp[3];
|
||||
int x;
|
||||
int swap;
|
||||
|
||||
x = 0;
|
||||
temp[0] = i;
|
||||
temp[1] = j;
|
||||
temp[2] = k;
|
||||
while (x < 3)
|
||||
{
|
||||
j = 0;
|
||||
while (j < 2)
|
||||
{
|
||||
if (temp[j] > temp[j + 1])
|
||||
{
|
||||
swap = temp[j];
|
||||
temp[j] = temp[j + 1];
|
||||
temp[j + 1] = swap;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return (temp[1]);
|
||||
}
|
28
d09/ex06/ft_destroy.c
Normal file
28
d09/ex06/ft_destroy.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_destroy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 23:41:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 04:01:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ft_ultimator.h"
|
||||
|
||||
void ft_destroy(char ***factory)
|
||||
{
|
||||
while (*factory != 0)
|
||||
{
|
||||
while (**factory != 0)
|
||||
{
|
||||
free(**factory);
|
||||
**factory++;
|
||||
}
|
||||
free(*factory);
|
||||
*factory++;
|
||||
}
|
||||
}
|
24
d09/ex07/ft_collatz_conjecture.c
Normal file
24
d09/ex07/ft_collatz_conjecture.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_collatz_conjecture.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 01:39:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 04:01:26 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
unsigned int ft_collatz_conjecture(unsigned int base)
|
||||
{
|
||||
static unsigned int i = 0;
|
||||
|
||||
i++;
|
||||
if (base == 1)
|
||||
return (i);
|
||||
else if (base % 2 == 0)
|
||||
return (ft_collatz_conjecture(base / 2));
|
||||
else
|
||||
return (ft_collatz_conjecture(base * 3 + 1));
|
||||
}
|
81
d09/ex08/ft_spy.c
Normal file
81
d09/ex08/ft_spy.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_spy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 01:58:29 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/04 04:01:16 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
write(1, str, 1);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void low(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (*str >= 'A' && *str <= 'Z')
|
||||
{
|
||||
*str += 32;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int is_alert(char *str, char *find)
|
||||
{
|
||||
while (*str == ' ' || *str == '\t')
|
||||
str++;
|
||||
while (*str && *find && *str == *find)
|
||||
{
|
||||
str++;
|
||||
find++;
|
||||
}
|
||||
if (*find == '\0' && (*str == '\0' || *str < 33))
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_spy(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *a;
|
||||
char *b;
|
||||
char *c;
|
||||
|
||||
a = "president";
|
||||
b = "attack";
|
||||
c = "powers";
|
||||
i = 1;
|
||||
j = 0;
|
||||
while (i < argc)
|
||||
{
|
||||
low(argv[i]);
|
||||
if (is_alert(argv[i], a) ||
|
||||
is_alert(argv[i], b) ||
|
||||
is_alert(argv[i], c))
|
||||
ft_putstr("Alert!!!\n");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ft_spy(argc, argv);
|
||||
return (0);
|
||||
}
|
21
d09/ex09/where_am_i.sh
Normal file
21
d09/ex09/where_am_i.sh
Normal file
|
@ -0,0 +1,21 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# where_am_i.sh :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/11/04 03:35:14 by gtertysh #+# #+# #
|
||||
# Updated: 2016/11/04 04:01:02 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
||||
IPS=$(ifconfig | grep "inet " | cut -d " " -f2)
|
||||
|
||||
if [ -z "$IPS" ]
|
||||
then
|
||||
echo "Je suis perdu!"
|
||||
else
|
||||
echo $IPS | tr " " "\n"
|
||||
fi
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue