41 lines
815 B
C
41 lines
815 B
C
#include <stdio.h>
|
|
|
|
char *strcat(char *s, const char *t);
|
|
char *strcpy(char *t, const char *s);
|
|
size_t strlen(const char *s);
|
|
|
|
/* passes args to strcat, prints result */
|
|
int main(int argc, char *argv[])
|
|
{
|
|
if (argc < 3)
|
|
return 1;
|
|
char s[strlen(argv[1]) + strlen(argv[2])];
|
|
strcat(strcpy(s, argv[1]), argv[2]);
|
|
printf("%s\n", s);
|
|
}
|
|
|
|
/* strcat: concat string t to end of string s */
|
|
char *strcat(char *s, const char *t)
|
|
{
|
|
int slen = strlen(s);
|
|
return strcpy(s + slen, t) - slen;
|
|
}
|
|
|
|
/* strcpy: copy string s to t */
|
|
char *strcpy(char *t, const char *s)
|
|
{
|
|
char *tc = t;
|
|
while ((*t++ = *s++))
|
|
;
|
|
return tc;
|
|
}
|
|
|
|
/* strlen: return length of string s (without \0) */
|
|
size_t strlen(const char *s)
|
|
{
|
|
const char *sc = s;
|
|
while (*s++)
|
|
;
|
|
return s - sc - 1;
|
|
}
|