In C Programming:
struct _String {
char *data; // dynamically-allocated array to hold the characters
uint32_t length; // number of characters in the string
};
typedef struct _String String;
/
** The String is initialized to hold the values in *src.
*
* Pre:
* *pSrc is C string with length up to slength (excludes null char)
* Post on success:
* A new, proper String object S is created such that:
* S.pData != pSrc->pData
* Up to slength characters in *pSrc are copied into dest->data
* (after dynamic allocation) and the new string is terminated
* with a '\0'
* S.length is set to the number of characters copied from *pSrc;
* this is no more than slength, but will be less if a '\0' is
* encountered in *pSrc before slength chars have occurred
* Post on failure:
* NULL is returned
*
* Returns:
* pointer to the new String object;
* NULL value if some error occurs
*/
String* String_Create(const char* const pSrc, uint32_t slength) {
/// Implement this function!! ///
return NULL;
}
/** Erases a specified sequence of characters from a String.
*
* Pre:
* *pSrc is a proper String object
* startIdx + length <= src->length
* Post:
* no memory leaks have occurred
* the specified range of characters have been removed
* *pSrc is proper
*
* Returns:
* if successful, pSrc
* NULL if failure occurs
*/
String* String_Erase(String* const pSrc, uint32_t start, uint32_t length) {
/// Implement this function!! ///
return NULL;
}