Your mission
Write a function named replace_and_flip that processes a string and prints the result to standard output using write. All allocated memory must be freed before returning. Rules: - A word is a sequence of non-space characters separated by spaces. - If total words < 9 or total words is even (including empty or space-only strings), print a copy of the string followed by " \n". - If total words >= 9 and odd: 1. Replace 2nd word occurrences with case-flipped 6th word. 2. Replace 6th word with original 2nd word. 3. Insert (total_words + 2) after the middle word. 4. Print transformed string followed by " \n".
See it in action
replace_and_flip("Run go fast go and lO jump go here");Run Lo fast Lo and 11 go jump Lo here \nreplace_and_flip("one two three four five");one two three four fivereplace_and_flip("one two three four five six seven eight nine ten");one two three four five six seven eight nine tenreplace_and_flip("a CAT b c d DOG e f CAT g h");a dog b c d CAT 13 e f dog g h \nreplace_and_flip(" HELLO WORLD foo bar mid TEST baz WORLD end ");HELLO test foo bar mid 11 WORLD baz test end \n
Your checklist
Constraints
- Expected file
replace_and_flip.c- Allowed functions
mallocfreewrite- Allowed headers
stdlib.hunistd.h
