Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 4: String Operations, Pointers, and C Library Functions (20 pts) You ma

ID: 3648699 • Letter: Q

Question

Question 4: String Operations, Pointers, and C Library Functions (20 pts)

You may only use pointers, not array, in the following exercises.
a. [5] Complete the following function that returns the length of string s.
int strlen(char *s)
{
// YOUR CODE
}
b. [5] Complete the following function that copies the string s2 to s1. Assume that s1 has sufficient storage.
int strcpy(char *s1, char *s2)
{
// YOUR CODE
}

c. [5] Complete the following function that compares two strings s1 and s2 lexicographically. Return 0 if the two strings are equal, -1 if s1 is less than s2, or 1 if s1 is greater than s2. The following are examples of lexicographical comparison results:

Explanation / Answer

int strlen(char *s) { int count = 0; char* ref = s; while(ref!=null){ ref=ref+1; count++; } return count; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote