update stuff
This commit is contained in:
parent
5973022688
commit
544ed8b045
194 changed files with 2060 additions and 1464 deletions
56
stdme/src/str/str_find_str.c
Normal file
56
stdme/src/str/str_find_str.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_str.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:53:53 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/str/str.h"
|
||||
|
||||
const char *str_find_str(t_const_str str, t_const_str to_find)
|
||||
{
|
||||
t_str needle;
|
||||
t_str haystack;
|
||||
|
||||
if (*to_find == '\0')
|
||||
return (str);
|
||||
while (*str)
|
||||
{
|
||||
haystack = (t_str)str;
|
||||
needle = (t_str)to_find;
|
||||
while (*haystack && *haystack == *needle)
|
||||
{
|
||||
haystack++;
|
||||
needle++;
|
||||
}
|
||||
if (*needle == '\0')
|
||||
return (str);
|
||||
str++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*R
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3)
|
||||
return (2);
|
||||
printf("HAYSTACK = '%s'\n", argv[1]);
|
||||
printf(" NEEDLE = '%s'\n", argv[2]);
|
||||
|
||||
printf("libc: %p : '%s'\n", str_find_str(argv[1], argv[2]),
|
||||
str_find_str(argv[1],
|
||||
argv[2]));
|
||||
printf(" ft : %p : '%s'\n",
|
||||
str_find_str(argv[1], argv[2]),
|
||||
str_find_str(argv[1], argv[2]));
|
||||
}
|
||||
R*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue