ft_search_pos_char.c 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_search_pos_char.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <marvin@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/10/12 18:07:23 by mazimi #+# #+# */
  9. /* Updated: 2016/10/29 14:42:41 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. /*
  14. ** Return string's position of first occurence of searched char
  15. ** If char not found, return '-1'
  16. */
  17. int ft_search_pos_char(const char *s1, char c)
  18. {
  19. int i;
  20. if (s1 == NULL)
  21. return (-1);
  22. i = -1;
  23. while (s1[++i] != '\0')
  24. if (s1[i] == c)
  25. return (i);
  26. if (s1[i] == c)
  27. return (i);
  28. return (-1);
  29. }