-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnmatch.c
35 lines (32 loc) · 819 Bytes
/
nmatch.c
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
/*
** EPITECH PROJECT, 2018
** nmatch Yoann ABBES
** File description:
** nmatch Yoann ABBES
*/
#include <unistd.h>
#include "my.h"
int count_comb(char const *s1, char const *s2)
{
if (*s1 == *s2) {
if (*s2 != '\0')
return (count_comb(s1 + 1, s2 + 1));
else
return (1);
} else {
if (*s2 == '*' && *s1 == '\0' && *(s2 + 1) == '\0')
return (1);
if (*s2 == '*' && *s1 == '\0' && *(s2 + 1) != '\0')
return (count_comb(s1, s2 + 1));
if (*s2 == '*' && *s1 != '\0')
return (count_comb(s1 + 1, s2) + count_comb(s1, s2 + 1));
}
return (0);
}
int nmatch(char const *s1, char const *s2)
{
if (handle_error(s1, s2) == 2)
return (count_comb(s1, s2));
else
return (handle_error(s1, s2));
}