Created
November 26, 2009 07:17
-
-
Save shaobin0604/243298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Exercise 5-3. Write a pointer version of the function strcat that we | |
| * showed in Chapter 2:strcat(s, t) copies the string t to the end of s. | |
| */ | |
| #include <stdio.h> | |
| void my_strcat(char *s, char *t) | |
| { | |
| while (*s) | |
| s++; | |
| while (*s++ = *t++) | |
| ; | |
| } | |
| int main(void) | |
| { | |
| char testbuff[128]; | |
| char *test[] = | |
| { | |
| "", | |
| "1", | |
| "12", | |
| "123", | |
| "1234" | |
| }; | |
| size_t numtests = sizeof test / sizeof test[0]; | |
| size_t thistest; | |
| size_t inner; | |
| for(thistest = 0; thistest < numtests; thistest++) | |
| { | |
| for(inner = 0; inner < numtests; inner++) | |
| { | |
| strcpy(testbuff, test[thistest]); | |
| my_strcat(testbuff, test[inner]); | |
| printf("[%s] + [%s] = [%s]\n", test[thistest], test[inner], testbuff); | |
| } | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment