init
This commit is contained in:
70
Correction/dfdgdf/ex04/ft_strstr.c
Normal file
70
Correction/dfdgdf/ex04/ft_strstr.c
Normal file
@ -0,0 +1,70 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/21 12:35:36 by jmendez #+# #+# */
|
||||
/* Updated: 2022/07/25 16:56:29 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *ft_strstr(char *str, char *to_find)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (to_find[j] == '\0')
|
||||
return (str);
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == to_find[j])
|
||||
{
|
||||
while (str[i] == to_find[j])
|
||||
{
|
||||
i++;
|
||||
j++;
|
||||
if (to_find[j] == '\0')
|
||||
return (&str[i - j]);
|
||||
}
|
||||
i = i - j;
|
||||
}
|
||||
j = 0;
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main (void) {
|
||||
char haystack1[20] = "TutorialsPoint";
|
||||
char needle1[10] = "Pint";
|
||||
char *ret1;
|
||||
|
||||
ret1 = strstr(haystack1, needle1);
|
||||
|
||||
printf("The substring is: %s\n", ret1);
|
||||
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
||||
char haystack2[20] = "TutorialsPoint";
|
||||
char needle2[10] = "Pint";
|
||||
char *ret2;
|
||||
|
||||
ret2 = ft_strstr(haystack2, needle2);
|
||||
|
||||
printf("The substring is: %s\n", ret2);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user