Compare commits
2 Commits
958448ca4e
...
8371b01390
Author | SHA1 | Date | |
---|---|---|---|
|
8371b01390 | ||
|
3e9f5e829f |
3
Makefile
3
Makefile
@ -1,8 +1,5 @@
|
|||||||
SRCS = parsing.c \
|
SRCS = parsing.c \
|
||||||
utils/ft_isnum.c \
|
utils/ft_isnum.c \
|
||||||
utils/putchar.c \
|
|
||||||
utils/putnum.c \
|
|
||||||
utils/putstr.c \
|
|
||||||
utils/ft_atoi.c \
|
utils/ft_atoi.c \
|
||||||
main.c \
|
main.c \
|
||||||
time.c \
|
time.c \
|
||||||
|
9
print.c
9
print.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/27 11:33:33 by cchauvet #+# #+# */
|
/* Created: 2023/04/27 11:33:33 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/04/27 11:43:42 by cchauvet ### ########.fr */
|
/* Updated: 2023/05/17 13:22:19 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,12 +30,7 @@ static void print(t_data *data, size_t id, char *str)
|
|||||||
if (stop == false)
|
if (stop == false)
|
||||||
{
|
{
|
||||||
time = get_time();
|
time = get_time();
|
||||||
ft_putnum(time, 7);
|
printf("%zu %zu %s\n", time, id, str);
|
||||||
ft_putchar(' ');
|
|
||||||
ft_putnum(id + 1, 3);
|
|
||||||
ft_putchar(' ');
|
|
||||||
ft_putstr(str);
|
|
||||||
ft_putchar('\n');
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&data->print_mutex);
|
pthread_mutex_unlock(&data->print_mutex);
|
||||||
}
|
}
|
||||||
|
9
print2.c
9
print2.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/27 11:41:14 by cchauvet #+# #+# */
|
/* Created: 2023/04/27 11:41:14 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/04/27 11:41:46 by cchauvet ### ########.fr */
|
/* Updated: 2023/05/17 13:21:33 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,11 +22,6 @@ void print_died(t_philo *philo)
|
|||||||
data = philo->data;
|
data = philo->data;
|
||||||
time = get_time();
|
time = get_time();
|
||||||
pthread_mutex_lock(&data->print_mutex);
|
pthread_mutex_lock(&data->print_mutex);
|
||||||
ft_putnum(time, 7);
|
printf("%7zu %3zu %s\n", time, philo->id, "died");
|
||||||
ft_putchar(' ');
|
|
||||||
ft_putnum(philo->id + 1, 3);
|
|
||||||
ft_putchar(' ');
|
|
||||||
ft_putstr("died");
|
|
||||||
ft_putchar('\n');
|
|
||||||
pthread_mutex_unlock(&data->print_mutex);
|
pthread_mutex_unlock(&data->print_mutex);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* putchar.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/27 11:28:09 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/04/27 11:28:10 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putchar(char c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* putnum.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/27 11:28:00 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/04/27 11:28:01 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
static size_t get_size(size_t num)
|
|
||||||
{
|
|
||||||
size_t nb_digit;
|
|
||||||
size_t rest;
|
|
||||||
|
|
||||||
nb_digit = 0;
|
|
||||||
if (num == 0)
|
|
||||||
nb_digit++;
|
|
||||||
rest = num;
|
|
||||||
while (rest != 0)
|
|
||||||
{
|
|
||||||
nb_digit++;
|
|
||||||
rest = rest / 10;
|
|
||||||
}
|
|
||||||
return (nb_digit);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_putdigit(size_t num)
|
|
||||||
{
|
|
||||||
if (num > 9)
|
|
||||||
{
|
|
||||||
ft_putdigit(num / 10);
|
|
||||||
ft_putchar(num % 10 + 48);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_putchar(num + 48);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_putnum(size_t num, size_t padding)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
size = get_size(num);
|
|
||||||
while (i < padding - size)
|
|
||||||
{
|
|
||||||
ft_putchar('0');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_putdigit(num);
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/27 11:28:26 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/04/27 11:28:27 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i] != 0)
|
|
||||||
{
|
|
||||||
ft_putchar(str[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user