πŸ‘¨β€πŸ’»
Guide
Laura's GithubSimon's Github
  • What is this gitbook for?
  • πŸ› οΈUseful tools
    • 🏁Header files
    • 🧱C Structures
    • πŸ”—Linked Lists (todo)
    • πŸ“„Makefiles
    • πŸ”„Switch statement
    • πŸ—ƒοΈFile descriptors (FD)
  • πŸ–ŒοΈMiniLibX
    • MiniLibX Helper Function
    • MiniLibX Hook Examples
  • 0️⃣ Rank 00
    • Libft
      • πŸ“‘LIBC functions
        • ft_isalpha
        • ft_isdigit
        • ft_isalnum
        • ft_isascii
        • ft_isprint
        • ft_strlen
        • ft_memset
        • ft_bzero
        • ft_memcpy
        • ft_memmove
        • ft_strlcpy
        • ft_strlcat
        • ft_toupper
        • ft_tolower
        • ft_strchr
        • ft_strrchr
        • ft_strncmp
        • ft_memchr
        • ft_memcmp
        • ft_strnstr
        • ft_atoi
        • ft_calloc
        • ft_strdup
      • πŸ“‘Additional functions
        • ft_substr
        • ft_strjoin
        • ft_strtrim
        • ft_split
        • ft_itoa
        • ft_strmapi
        • ft_striteri
        • ft_putchar_fd
        • ft_putstr_fd
        • ft_putendl_fd
        • ft_putnbr_fd
      • πŸ“‘Bonus functions
        • ft_lstnew
        • ft_lstadd_front
        • ft_lstsize
        • ft_lstlast
        • ft_lstadd_back
        • ft_lstdelone
        • ft_lstclear
        • ft_lstiter
        • ft_lstmap
  • 1️⃣ Rank 01
    • Born2beRoot
      • πŸ“ What's a virtual machine ?
      • πŸ“ Install your virtual machine
      • πŸ“ P2P Evaluation - Questions
    • ft_printf
      • β–ͺ️Variadic functions
      • β–ͺ️Building the thing
    • get_next_line
      • β–ͺ️open() & read()
      • β–ͺ️Static variables
      • β–ͺ️Building the thing
      • β–ͺ️Commented solution
  • 2️⃣ Rank 02
    • so_long
      • β–ͺ️Understand so_long
      • β–ͺ️Core concepts
      • β–ͺ️Building the thing
    • pipex
      • β–ͺ️Understand pipex
      • β–ͺ️Functions used
      • β–ͺ️Building the thing
    • minitalk
      • β–ͺ️Understand minitalk
      • β–ͺ️Functions used
      • β–ͺ️Building the thing
    • push_swap
      • β–ͺ️Algorithms
      • β—ΎBuilding the thing
    • FdF
      • πŸ—‘οΈUnderstand FdF
      • πŸ—‘οΈGraphics programming
      • πŸ—‘οΈBuilding the thing
  • 3️⃣ RANK 03
    • Philosophers
      • β–ͺ️Understand Philosophers
      • β–ͺ️Functions used
      • β–ͺ️Building the thing
    • Minishell
      • β–ͺ️Understand Minishell
      • β–ͺ️Functions
      • β—ΎBuilding the thing
  • 4️⃣ RANK 04
    • CPP (00 - 04) (doing)
      • CPP00
      • CPP01
      • CPP02
      • CPP03
      • CPP04 (doing)
    • NetPractice
      • Theory
      • Level 1 & 2
    • MiniRT
      • Understand MiniRT
      • Building the thing
  • 5️⃣ RANK 05
    • CPP (05-09) (to-do)
      • CPP05
      • CPP06 (to-do)
      • CPP07
      • CPP08 (to-do)
      • CPP09 (to-do)
    • Inception (doing)
      • πŸ•“The basics (Docker, Images, etc...)
      • Project Files
    • webserv (to-do)
  • 6️⃣ rank 06
    • ft_transcendence (to-do)
  • πŸ›‚Exams
    • Exam Rank 02
      • Level 1
        • first_word
        • fizz_buzz
        • *ft_putstr
        • *ft_strcpy
        • *ft_strlen
        • ft_swap
        • repeat_alpha
        • rev_print
        • rot_13
        • rotone
        • search_and_replace
        • ulstr
      • Level 2
        • alpha_mirror
        • camel_to_snake
        • do_op
        • *ft_atoi
        • *ft_strcmp
        • ft_strcspn
        • ft_strspn
        • *ft_strdup
        • ft_strpbrk
        • ft_strrev
        • inter
        • last_word
        • ft_is_power_2
        • max
        • print_bits
        • reverse_bits
        • wdmatch
        • swap_bits
        • union
        • snake_to_camel
      • Level 3
        • add_prime_sum
        • epur_str
        • expand_str
        • ft_atoi_base
        • ft_list_size
        • ft_range
        • ft_rrange
        • hidenp
        • lcm
        • paramsum
        • pgcd
        • print_hex
        • rstr_capitalizer
        • str_capitalizer
        • tab_mult
      • Level 4
        • flood_fil
        • fprime
        • ft_split
        • ft_itoa
        • ft_list_foreach
        • ft_list_remove
        • rev_wstr
        • rotstring
        • sort_int_tab
        • sort_list
    • Exam Rank 03
    • Exam Rank 04
    • Exam Rank 05
      • Module 0
  • πŸ‘₯Team
Powered by GitBook
On this page
  • Subject
  • Man page
  • Commented solution

Was this helpful?

  1. Exams
  2. Exam Rank 02
  3. Level 2

ft_strpbrk

Subject

Assignment name	: ft_strpbrk
Expected files	: ft_strpbrk.c
Allowed functions: None
---------------------------------------------------------------

Reproduce exactly the behavior of the function strpbrk
(man strpbrk).

The function should be prototyped as follows:

char	*ft_strpbrk(const char *s1, const char *s2);

Man page

STRPBRK(3) (simplified)

NAME
     strpbrk –- locate multiple characters in string
LIBRARY
     Standard CΒ Library (libc, -lc)
SYNOPSIS
     #include <string.h>
     char *strpbrk(const char *s, const char *charset);

DESCRIPTION
     The strpbrk() function locates in the null-terminated string s the first
     occurrence of any character in the string charset and returns a pointer to this
     character.  If no characters from charset occur anywhere in s strpbrk()
     returns NULL.
RETURN VALUES
     The strpbrk() function return a pointer to the first occurence of any character
     in the string,if no characters occur anywhere in s, strpbrk() returns NULL.

Commented solution

ft_strpbrk()
char	*ft_strpbrk(const char *s1, const char *s2)
{
	int i;
	int	j;

	i = 0;
	while (s1[i])
	{
		j = 0;
		while (s2[j])
		{
			if (s2[j] == s1[i])
				return (s1[i]);
			j++;
		}
		i++;
	}
	return (NULL);
}
Previous*ft_strdupNextft_strrev

Last updated 1 year ago

Was this helpful?

πŸ›‚