61 lines
3.0 KiB
C
61 lines
3.0 KiB
C
/// @file
|
|
/// @brief Task2: Structure definitions and function declarations
|
|
|
|
#pragma once
|
|
|
|
#include <stddef.h> // size_t
|
|
|
|
/// @brief Compares two strings 'a' and 'b' lexicographically, byte-by-byte
|
|
/// until the first occurence of a null termination.
|
|
/// Note: The null termination character is part of the comparison
|
|
/// @param a Pointer to the first character range
|
|
/// @param b Pointer to the second character range
|
|
/// @return The function returns
|
|
/// - a negative value, if 'a' is lexicographically ordered before 'b',
|
|
/// - a positive value, if 'a' is lexicographically ordered after 'b',
|
|
/// - zero, if 'a' and 'b' are equal
|
|
/// @note This function requires:
|
|
/// - 'a' and 'b' point to null-terminated ranges
|
|
int task2_compare(const char* a, const char* b);
|
|
|
|
/// @brief Compares two strings 'a' and 'b' lexicographically, byte-by-byte until
|
|
/// - the occurence of a null termination, but at most
|
|
/// - up to the preset maximum 'count' of characters to be compare
|
|
/// Note: The null termination character is part of the comparison
|
|
/// @param a Pointer to the first character range
|
|
/// @param b Pointer to the second character range
|
|
/// @param count Maximum number of characters to be compared
|
|
/// @return The function returns
|
|
/// - a negative value, if 'a' is lexicographically ordered before 'b',
|
|
/// - a positive value, if 'a' is lexicographically ordered after 'b',
|
|
/// - zero, if 'a' and 'b' are equal
|
|
/// @note This function requires:
|
|
/// - 'a' and 'b' point to a null-terminated ranges
|
|
int task2_compare_n(const char* a, const char* b, size_t count);
|
|
|
|
/// @brief Copies a string until the first occurence of a null termination.
|
|
/// from a source 'src' to destination 'dest' location
|
|
/// @param dest Pointer to the first character of the destination range
|
|
/// @param src Pointer to the first character of the source range
|
|
/// @return Pointer to the first character of the destination range
|
|
/// @note This function requires:
|
|
/// - source and destination ranges do not overlap
|
|
/// - the source points to a null-terminated range
|
|
/// - the destination range fits the size of the source range (including a null termination character)
|
|
char* task2_copy(char* dest, const char* src);
|
|
|
|
/// @brief Copies a string from a source 'src' to destination 'dest' range:
|
|
/// - If the preset maximum 'count' of characters to be copied is reached before a null termination occurs in 'src' the
|
|
/// resulting destination range will not be null terminated, else
|
|
/// - the termination character is also placed in the destination range.
|
|
/// @param dest Pointer to the first character of the destination range
|
|
/// @param src Pointer to the first character of the source range
|
|
/// @param count Maximum number of characters to be copied
|
|
/// @return Pointer to the first character of the destination range
|
|
/// @note This function requires:
|
|
/// - source and destination ranges do not overlap
|
|
/// - the source points to a null-terminated range
|
|
/// - the destination range can fit 'count' characters
|
|
char* task2_copy_n(char* dest, const char* src, size_t count);
|
|
|