Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sh-5.0$ cat 1.c
- #include <stdio.h>
- #include <stdlib.h>
- #define MAXLEN 100
- void strcat2(char *destination, char *source);
- int main()
- {
- // create a character array. All of these C strings are terminated with a '\0'
- char start[MAXLEN] = "This is a sentence looking for";
- char end[] = " an ending!";
- // strcat2 destination, source
- strcat2(start, end);
- // str is the same as &str[0] which is handed to printf and prints all the
- // up to '\0'
- printf("%s\n", start);
- }
- void strcat2(char *start, char *end)
- {
- // move pointer to end of start.
- while (*start++)
- ;
- // allows me to overwrite the null character
- start--;
- while ((*start++ = *end++))
- ;
- }
- sh-5.0$ gcc 1.c
- sh-5.0$ ./a.out
- This is a sentence looking for an ending!
- sh-5.0$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement