Skip to content

Instantly share code, notes, and snippets.

@ayaderaghul
Last active April 20, 2018 09:14
Show Gist options
  • Save ayaderaghul/8ce9181fdd6e5044c222a0fadcb467eb to your computer and use it in GitHub Desktop.
Save ayaderaghul/8ce9181fdd6e5044c222a0fadcb467eb to your computer and use it in GitHub Desktop.
int ft_strcmp(const char *s1, const char *s2)
{
int i;
i = 0;
while (s1[i] || s2[i])
{
if (s1[i] != s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
++i;
}
return (0);
}
#include <stdio.h>
#include<string.h>
int ft_strcmp(const char *s1, const char *s2);
int main()
{
char *s1 = "\0";
char *s2 = "\200";
int i1 = strcmp(s1, s2);
int i2 = ft_strcmp(s1, s2);
char *s3 = "\x12\xff\x65\x12\xbd\xde\xad";
char *s4 = "\x12\x02";
int i3 = strcmp(s3, s4);
int i4 = ft_strcmp(s3, s4);
printf("strcmp: %d\nft_strcmp: %d\nstrcmp: %d\nft_strcmp: %d\n", i1, i2, i3\
, i4);
return 0;
}
@pgiammel
Copy link

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

	i = 0;
	while (s1[i] || s2[i])
	{
		if (s1[i] != s2[i])
			return ((unsigned char)s1[i] - (unsigned char)s2[i]);
		++i;
	}
	return (0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment