count_char_str.c 1.1 KB

123456789101112131415161718192021222324252627282930
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* count_char_str.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <marvin@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/02/27 18:47:06 by mazimi #+# #+# */
  9. /* Updated: 2016/02/27 18:47:15 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. /*
  14. ** Count number of character occurences in a string.
  15. */
  16. int count_char_str(char *str, char c)
  17. {
  18. int i;
  19. int occ;
  20. occ = 0;
  21. i = -1;
  22. while (str[++i] != '\0')
  23. if (str[i] == c)
  24. occ++;
  25. return (occ);
  26. }