Revert "Added strlen function (#606)" (#607)

This reverts commit 598630cecb.
This commit is contained in:
Krishna Vedala 2020-09-23 14:33:57 -04:00 committed by GitHub
parent 598630cecb
commit 526c898644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 88 deletions

View File

@ -382,7 +382,3 @@
* [Shell Sort](https://github.com/TheAlgorithms/C/blob/master/sorting/shell_sort.c)
* [Shell Sort2](https://github.com/TheAlgorithms/C/blob/master/sorting/shell_sort2.c)
* [Stooge Sort](https://github.com/TheAlgorithms/C/blob/master/sorting/stooge_sort.c)
## Strings
* [Strlen](https://github.com/TheAlgorithms/C/blob/master/strings/strlen.c)
* [Strlen Recursion](https://github.com/TheAlgorithms/C/blob/master/strings/strlen_recursion.c)

View File

@ -1,46 +0,0 @@
/**
* @file
* @brief Program to calculate length of string.
*
* @author [Du Yuanchao](https://github.com/shellhub)
*/
#include <assert.h>
#include <string.h>
/**
* @brief Returns the length of string
* @param str the pointer of string.
* @return the length of string.
*/
int length(const char *str)
{
int count = 0;
for (int i = 0; *(str + i) != '\0'; ++i)
{
count++;
}
return count;
}
/**
* @brief Test function
* @return void
*/
static void test()
{
assert(length("") == strlen(""));
assert(length(("a")) == strlen("a"));
assert(length("abc") == strlen("abc"));
assert(length("abc123def") == strlen("abc123def"));
assert(length("abc\0def") == strlen("abc\0def"));
}
/**
* @brief Driver Code
* @returns 0 on exit
*/
int main()
{
test();
return 0;
}

View File

@ -1,38 +0,0 @@
/**
* @file
* @brief Program to calculate length of string using recursion.
*
* @author [Du Yuanchao](https://github.com/shellhub)
*/
#include <assert.h>
#include <string.h>
/**
* @brief Returns the length of string using recursion
* @param str the pointer of string.
* @return the length of string.
*/
int length(const char *str) { return *str == '\0' ? 0 : 1 + length(++str); }
/**
* @brief Test function
* @return void
*/
static void test()
{
assert(length("") == strlen(""));
assert(length(("a")) == strlen("a"));
assert(length("abc") == strlen("abc"));
assert(length("abc123def") == strlen("abc123def"));
assert(length("abc\0def") == strlen("abc\0def"));
}
/**
* @brief Driver Code
* @returns 0 on exit
*/
int main()
{
test();
return 0;
}