Skip to content

Commit

Permalink
Update strtoarr.c
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePrimeJnr authored Jul 26, 2023
1 parent 3f9ce6c commit e03f24e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions strtoarr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,23 @@ char **strtoarr(char *str, char delim)

return (arr);
}

/**
* _strncmp - compares 2 strings till n char
* @str1: first string to be compared with
* @str2: second string compared on/with first string
* @n: number of string to be compared
* Return: 0 if equal, positive if s1 < s2, negative if s1 > s2
*/
int _strncmp(const char *str1, const char *str2, size_t n)
{
for (size_t i = 0; i < n; i++)
{
if (str1[i] == '\0' || str2[i] == '\0')
return str1[i] - str2[i];

if (str1[i] != str2[i])
return str1[i] - str2[i];
}
return 0;
}

0 comments on commit e03f24e

Please sign in to comment.