Okayy, So.
I'm required to make a new set of functions for the <string.h> library and am confused on a few things, and am wondering if anyone can help me out. I'll toss out the ones I'm struggling with.
int mystrcmp(const char* s1, const char* s2);
This function will compare two strings lexically. If both strings are identical, it will return a 0.
Otherwise, if string s1 is greater than s2 it will return an integer greater than 0. If s2 is greater
than s1 it will return an integer less than zero. The absolute value returned will represent the
number of characters that are needed to be checked before the function can return. All things
being equal, a longer word is greater than a shorter word.
For example, if s1 is “Apple” and s2 is “Ball”, then s1 < s2 and only the first characters need to be
compared so -1 will be returned.
If s1 is “This” and s2 is “That” then s1 > s2 and since 3 characters need to be compared before
we can determine this, the function will return +3.
If s1 is “go” and s2 is “goes”, then s1<s2 since s1 is shorter than s2 and both words are identical
until s1 runs out of letters. The function will return -3 since this determination could not be
determined until the third letter.
int mystrstr(const char* s1, const char* s2);
This function will look in s1 for a substring exactly matching the string in s2. If it finds such a
substring, it will return an integer containing the location of the first character of the match
(counting from zero). If there is no match, it returns -1.
Example: s1 contains “The man goes to the store.” And s2 contains “sto”. The function will
return 20, since “sto” begins at the 21st character of s1.
char* mywhine(const char* s1, const int whines);
This function will take a string s1, and append the word “pretty “ the number of times specified
by whines followed by the word “ please!” The resulting new string must follow the standard
rules of English grammar.
For example, if s1 contains “Can I play with my friends?” and the function is called as
mywhine(s1,3), the returned string will contain:
“Can I play with my friends? Pretty pretty pretty please!”
char* myhiccups(const char* s1);
This function will take string s1 and insert the phrase, “—hick—“ between every third word. The
function will return the new phrase in a new string.
char* mypiglatin(const char* s1);
This function will parse each word in s1. For every word longer than 2 characters, it will take the
first letter off the front of each word and adding it to the end of the word. It then adds “ay” to
the end of the new word before putting the words back together in the same order. The
program should manage proper capitalization.
I understand the algorithm for them, I just don't know how to translate it into code.
I need it done for tomorrow, and I really need it xD
Thanks in advance.
Kevin.
edit: Solved one of the functions