please help me with this question in C language Someone accidentally deleted the
ID: 657714 • Letter: P
Question
please help me with this question in C language
Someone accidentally deleted the C standard library, so now you have to rewrite it from scratch. Start with implementing a safe string compare function with the following prototype. Make sure to validate all the arguments. For example (but not limited to) checking if s1 and s2 are NULL Compares at most n characters of string s1 to string s2. param s1 Location of the first string buffer. param s2 Location of the second string buffer. param n maximum number of characters to compare. return integer less than 0 if s1 s2. intExplanation / Answer
int strcmp(char *s1, char *s2, int n)
{
while ((*s1 || *s2) && n--)
if (*s1++ != *s2++)
return (*--s1 - *--s2);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.