-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marilia Brito Passos
committed
Apr 17, 2023
1 parent
3a25d0f
commit 05b0219
Showing
6 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strchr.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: mbrito-p <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/04/17 20:33:14 by mbrito-p #+# #+# */ | ||
/* Updated: 2023/04/17 20:41:01 by mbrito-p ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
// The strchr function in C is used to search a given string | ||
// (i.e., a sequence of characters) for the first occurrence | ||
// of a specified character.The str parameter is a pointer to the string | ||
// in which the search is to be performed. | ||
// The c parameter is the character that you want to search for in the string. | ||
// The function returns a pointer to the first occurrence | ||
// of the character c in the string str. If the character | ||
// is not found, the function returns NULL. | ||
#include "libft.h" | ||
|
||
char *ft_strchr(const char *s, int c) | ||
{ | ||
while (*s != '\0') { | ||
if (*s == c) { | ||
return (char *)s; | ||
} | ||
s++; | ||
} | ||
if (*s == c) { | ||
return (char *)s; | ||
} | ||
return NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,19 @@ | |
/* By: mbrito-p <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/04/12 20:20:59 by mbrito-p #+# #+# */ | ||
/* Updated: 2023/04/14 20:57:10 by mbrito-p ### ########.fr */ | ||
/* Updated: 2023/04/17 20:41:41 by mbrito-p ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int main(void) | ||
{ | ||
char str1[20] = "Hello, "; | ||
char *str2 = "world!"; | ||
size_t dest_size = sizeof(str1); | ||
size_t result = ft_strlcat(str1, str2, dest_size); | ||
printf("Result: %zu, Destination string: %s\n", result, str1); | ||
|
||
return 0; | ||
} | ||
|
||
int main() { | ||
char str[] = "hello world"; | ||
char *ptr = ft_strchr(str, 'w'); | ||
if (ptr != NULL) { | ||
printf("The character 'w' was found in the string at position %ld.\n", ptr - str); | ||
} else { | ||
printf("The character 'w' was not found in the string.\n"); | ||
} | ||
return 0; | ||
} |