mirror of https://github.com/TheAlgorithms/C
This reverts commit 598630cecb
.
This commit is contained in:
parent
598630cecb
commit
526c898644
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue