Skip to content

Instantly share code, notes, and snippets.

@aliou
Created November 24, 2012 18:21
Show Gist options
  • Save aliou/4140785 to your computer and use it in GitHub Desktop.
Save aliou/4140785 to your computer and use it in GitHub Desktop.
hidenp
/*
** hidenp.c for hidenp in /exam//rendu/ex_5
**
** Made by aliou diallo
** Login <[email protected]>
**
** Started on Sat Oct 13 10:25:30 2012 aliou diallo
** Last update Sat Oct 13 11:06:32 2012 aliou diallo
*/
int my_putchar(char c)
{
write(1, &c, 1);
}
int match(char *needle, char *haystack)
{
int i;
int j;
i = 0;
j = 0;
while (haystack[i] != 0)
{
while (haystack[i] != needle[j] && haystack[i] != '\0' && needle[j] != '\0')
i = i + 1;
if (needle[j] == haystack[i])
{
i = i + 1;
j = j + 1;
}
if (needle[j] == '\0')
return (1);
if (haystack[i] == '\0')
return (0);
// if (needle[j] != haystack[i] && haystack[i] != '\0')
// j = 0;
}
}
int main(int ac, char **av)
{
if (ac == 3)
{
if (match(av[1], av[2]) == 1)
my_putchar('1');
else
my_putchar('0');
}
my_putchar('\n');
}
/*
** main.c for hidenp in /exam//rendu/ex_8
**
** Made by aliou diallo
** Login <[email protected]>
**
** Started on Sat Oct 27 11:46:26 2012 aliou diallo
** Last update Sat Oct 27 11:56:53 2012 aliou diallo
*/
void my_putc(char c)
{
write(1, &c, 1);
}
int hidenp(char *needle, char *haystack)
{
int i;
int j;
i = 0;
j = 0;
while (needle[i] != '\0' && haystack[j] != '\0')
{
if (needle[i] == haystack[j])
i = i + 1;
j = j + 1;
}
if (needle[i] == '\0')
{
my_putc('1');
return (0);
}
if (haystack[j] == '\0')
my_putc('0');
return (0);
}
int main(int ac, char **av)
{
if (ac == 3)
hidenp(av[1], av[2]);
my_putc('\n');
return (0);
}
/*
** main.c for in /exam//rendu/ex_4
**
** Made by aliou diallo
** Login <[email protected]>
**
** Started on Sat Nov 24 11:00:25 2012 aliou diallo
** Last update Sat Nov 24 11:06:23 2012 aliou diallo
*/
void my_putcc(char c)
{
write(1, &c, 1);
}
void hidenp(char *needle, char *haystack)
{
while (*needle && *haystack)
{
if (*needle == *haystack)
*needle++;
*haystack++;
}
if (!*needle)
my_putcc('1');
if (*needle && !*haystack)
my_putcc('0');
}
int main(int ac, char **av)
{
if (ac == 3)
hidenp(av[1], av[2]);
my_putcc('\n');
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment