Implement the solutions to this exercise without using the standard library
(except stdbool.h
and stdio.h
).
You may implement as many additional functions as you deem useful (eg. your
own version of char to_upper(char c)
and
char to_lower(char c)
.
void capitalize(char string[]);
that capitalizes the given string.
For example,
char text[] = "The world is beautiful!";
void capitalize(text); // `text` becomes "The World Is Beautiful."
Name the source file: capitalize.c
// Return the number of characters in the string excluding the trailing '\0'.
size_t str_len(const char[] s);
// "Hello World!" => "hELLO wORLD!"
void str_inverse_case(char str[]);
// Return true if `str` starts with prefix, otherwise false.
bool str_starts_with(const char str[], const char prefix[]);
// true if `str` ends with suffix
bool str_ends_with(const char str[], const char suffix[]);
// number of occurences of `sub` in `str`
unsigned str_count(const char str[], const char sub[]);
// true if `str` only has ascii chars (a-z and A-Z; not extended ascii)
bool str_is_ascii(const char str[]);
// true if `str` only has digits
bool str_is_digit(const char str[]);
// position of first occurance of `sub` in `str` | -1
long str_index(const char str[], const char sub[]);
Design multiple appropriate test cases (input output combinations) before
implementing the above functions. Call the functions from within
main(.)
to make sure that the test cases pass.`void join(char* array[], std::size_t count, char str[], char sep[]);`
You may assume that the caller always passes a `str` that is large enough to
contain all of the joined strings including the separators between them.
`sep` can contain any number of characters that are inserted between the
strings in `array`. For example
char* array[] = {"Chris", "Pat", "Maria"};
char result[100];
join(array, 3, result, " | "); // => "Chris | Pat | Maria"
Name the source file: c-strings.c