Skip to content

Instantly share code, notes, and snippets.

@yclim95
Created May 25, 2022 01:52
Show Gist options
  • Save yclim95/9f7beaa1ed6a49d882d250d4c204131e to your computer and use it in GitHub Desktop.
Save yclim95/9f7beaa1ed6a49d882d250d4c204131e to your computer and use it in GitHub Desktop.
strrchr() in c
#include <stdio.h>

size_t	ft_strlen(const char *s)
{
	size_t	counter;

	counter = 0;
	while(s[counter] != '\0')
		counter++;
	return (counter);
}


char	*ft_strrchr(const char *s, int c)
{
	size_t	len;

	len = ft_strlen(s);
	while (s[len] != c && len != 0)
		len--;
	if (s[len] == c)
		return ((char *)(s + len));
	return (0);
}


int main()
{
   int len;
   const char str[] = "http://www.tutorialspoint.com";
   const char ch = '.';
   char *ret;

   ret = ft_strrchr(str, ch);

   printf("String after |%c| is - |%s|\n", ch, ret);
   
   return(0);
}
String after |.| is - |.com|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment