#include // Copies the C string pointed by source into the array pointed by dest
ID: 3883775 • Letter: #
Question
#include // Copies the C string pointed by source into the array pointed by destination, // including the terminating character (and stopping at that point). // To avoid overflows, the size of the array pointed by destination shall be long enough to contain // the same C string as source (including the terminating null character), and should not overlap // in memory w/ source. har·strcpy-nccare herconst char. p) { // Copies the first num characters of source to destination. If the end of the source C string (which is signaled // by a null-character) is found before num characters have been copied, destination is padded with zeros char* strncpy_(char* q, const char* p, size t n) // fill in code here // Returns the length of the C string str. // The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters // between the beginning of the string and the terminating null character (without including the terminating null character itself) Il size_t strlen_(const char* p) f // fill in code here // Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed // by the concatenation of both in destination. destination and source shall not overlap char* strcat_(char* s, const char* ct) t // fill in code hereExplanation / Answer
Hi, Please find my implementation of all required functions.
Please use these functions and call in Main function.
Please let me know in case of any issue.
int strlen_(const char * str)
{
int i = 0;
while (str[i] != '')
i++;
return i;
}
char * strcpy_(char * des,const char * src){
char * temp = des;
while(*src){
*temp = *src;
temp++;
src++;
}
return des;
}
char *strcat_(char *dest, const char *src)
{
int len;
int i;
len = my_strlen(dest);
i = 0;
while(src[i])
{
dest[len + i] = src[i];
i = i + 1;
}
dest[len + i] = '';
return (dest);
}
char *strncpy_(char *dest, const char *src, int n)
{
int i;
int max_str;
i = 0;
max_str = my_strlen(src);
while ( i < n)
{
dest[i] = src[i];
i = i + 1;
if (n >= max_str)
dest[max_str + 1] = '';
}
return (dest);
}
char *strncat_(char *dest, const char *src, int nb)
{
int dest_length;
int i;
dest_length = my_strlen(dest);
i = 0;
while (src[i] != '' && i < nb)
{
dest[dest_length + i] = src[i];
i = i + 1;
}
return (dest);
}
int compare(const char *p, const char *q) {
while(*p && (*p == *q))
{
p++;
q++;
}
return *(const unsigned char*)p - *(const unsigned char*)q;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.