Compare commits

..

2 Commits

Author SHA1 Message Date
Flinner Yuu a8a3cbe224
feat: 5-3 2022-07-18 08:15:40 +03:00
Flinner Yuu 8559d002a2
feat: .gitignore 2022-07-18 08:15:33 +03:00
2 changed files with 36 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.out

35
chapter-5/5-3.c Normal file
View File

@ -0,0 +1,35 @@
/* 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 <ctype.h>
#include <stdio.h>
// version 1
void my_strcat1(char *s, char *t) {
while (*s)
s++; // go to end of s
while ((*s = *t) != '\0') {
s++;
t++;
}
}
// version 2
void my_strcat2(char *s, char *t) {
while (*s)
s++; // go to end of s
while ((*s++ = *t++))
; // then copy
}
int main() {
char s[50] = "Hello, ";
char t[] = "world!";
my_strcat2(s, t);
printf("%s\n", s);
return 0;
}