aboutsummaryrefslogtreecommitdiff
path: root/rendu/inter/inter.c
blob: 1d5eeffbf41cc650c4d5606cbd54ce9fdb30c4e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   iter.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: exam <marvin@42.fr>                        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:00:51 by exam              #+#    #+#             */
/*   Updated: 2020/02/14 17:13:39 by exam             ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>

int		ft_strlen(char *s)
{
	int i;

	i = 0;
	while (s[i])
		i++;
	return (i);
}

void	ft_putchar(char c)
{
	write(1, &c, 1);
}

int	in_str(char *s, char c, int n)
{
	while (*s && n-- > 0)
		if (c == *s++)
			return (1);
	return (0);
}

int	main(int argc, char **argv)
{
	char *s1;
	char *s2;
	int		i;

	if (argc != 3)
	{
		write(1, "\n", 1);
		return (1);
	}
	s1 = argv[1];
	s2 = argv[2];
	i = 0;
	while (s1[i])
	{
		if (!in_str(s1, s1[i], i) && in_str(s2, s1[i], ft_strlen(s2)))
			ft_putchar(s1[i]);
		i++;
	}
	ft_putchar('\n');
	return (0);
}