This commit is contained in:
2026-05-10 19:34:35 +02:00
parent d65a736012
commit 01911bdd32
2 changed files with 28 additions and 2 deletions
+1
View File
@@ -14,5 +14,6 @@ char *strcat(char *dest, const char *src);
void strncpy(char* dst, const char* src, size_t n); void strncpy(char* dst, const char* src, size_t n);
int strncmp(const char* s1, const char* s2, size_t n); int strncmp(const char* s1, const char* s2, size_t n);
size_t strlen(const char* str); size_t strlen(const char* str);
int atoi(const char* str);
#endif #endif
+27 -2
View File
@@ -71,7 +71,6 @@ void strncpy(char* dst, const char* src, size_t n)
while(i++ != n && (*dst++ = *src++)); while(i++ != n && (*dst++ = *src++));
} }
/* /*
* strncmp - compare two strings up to n characters * strncmp - compare two strings up to n characters
* @s1: first string * @s1: first string
@@ -100,10 +99,36 @@ int strncmp(const char* s1, const char* s2, size_t n)
} }
} }
// BSD implementation /*
* strlen - get length of a string (BSD implementation)
* @str: NULL-terminated string
*
* Return:
* %len - length of string
*/
size_t strlen(const char* str) size_t strlen(const char* str)
{ {
const char* s; const char* s;
for (s = str; *s; ++s); for (s = str; *s; ++s);
return (s - str); return (s - str);
} }
/*
* atoi - ascii to integer (PureDOOM implementation)
* @str: ASCII string to convert
*
* Return:
* %i - integer represented in @str
*/
int atoi(const char* str)
{
int i = 0;
int c;
while ((c = *str++) != 0) {
i *= 10;
i += c - '0';
}
return i;
}