Question 0

What are the differences between the strlen() and sizeof() a char* string pointer in C? Why?

Question 1

Write the function

replace(char base[], char from[], char to[])

which finds the string 'from' in the string 'base' and replaces it with the string 'to'. You may assume that from and to are the same length. For example, the code

char string[] = "recieve";
replace(string, "ie", "ei");
//> should change 'string' to "receive".

Be careful not to assume the substring being replaced is singular, or that its own substrings are unique.

Do not rescan letters already checked/replaced

char string[] = "Msissisippi";
replace(string, "sis", "iss");
//> should change 'string' to "Mississippi" (.. and not miss the second "sis")

char string[] = " flajellate";
replace(string, "laj", "lag");
//> should change 'string' to "flagellate" (.. and not modify "lat")

Question 3

Are strlen() and sizeof() of the two string variables below different? (run the code to test your assumption - be sure to load < string.h> to get access to strlen())

Why is strlen() the same or different?

Why is sizeof() the same or different?

char* string0 = "hello";
char string1[] = "hello";
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.