init
This commit is contained in:
BIN
Correction/titou/ex04/a.out
Executable file
BIN
Correction/titou/ex04/a.out
Executable file
Binary file not shown.
61
Correction/titou/ex04/ft_strstr.c
Normal file
61
Correction/titou/ex04/ft_strstr.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 19:04:42 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 10:45:52 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strstr(char *str, char *to_find)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
|
||||
i = 0;
|
||||
if (to_find[0] == '\0')
|
||||
return (str);
|
||||
while (str[i] != 0)
|
||||
{
|
||||
j = 0;
|
||||
while (str[i + j] == to_find[j])
|
||||
{
|
||||
if (to_find[j + 1] == 0)
|
||||
return (&str[i]);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main (void) {
|
||||
char haystack1[20] = "TutorialsPointPoint";
|
||||
char needle1[10] = "Point";
|
||||
char *ret1;
|
||||
|
||||
ret1 = strstr(haystack1, needle1);
|
||||
|
||||
printf("The substring is: %s\n", ret1);
|
||||
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
||||
char haystack2[20] = "TutorialsPointPoint";
|
||||
char needle2[10] = "Point";
|
||||
char *ret2;
|
||||
|
||||
ret2 = ft_strstr(haystack2, needle2);
|
||||
|
||||
printf("The substring is: %s\n", ret2);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user