Turn in your functions and your test program. The test program should test all of the functions. Don't throw away tests after they work.
Functions strlen and strcpy were written in the lecture. You may feel free to use the lecture versions of those functions.
strcpy(s, "abcd"); strcat(s, "xyz");should end with array s holding null-terminated string "abcdxyz". Function strcat should presume that enough room is available in array s.
-1 | if s comes before t in alphabetical order |
0 | if s and t are identical |
1 | if s comes after t in alphabetical order |
Think about how to compare strings. You start with the first character of each string. You only continue to the next character if those characters are the same.
If s is a prefix of t (for example, if s is "abc" and t is "abcde"), then strcmp(s,t) should return -1. Similarly, if t is a prefix of s, then strcmp(s,t) should return 1.
You should use the standard ascii ordering of characters. You can compare two characters using comparisons such as < and >. Note that this will cause strcmp("DD","aa") to return -1, since character 'D' has a smaller ascii code than character 'a'. That is ok.
Note: There is a standard library function called strchr that behaves similarly to this function, but not quite the same. It returns the memory address of the character rather than its index.
Note: Function strchr should work correctly when character c is the null character. It should return the index where the null character is located (at the end of the string).