krx50301.c
来自「answer of the c programming language sec」· C语言 代码 · 共 67 行
C
67 行
/*
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.
implementation from chapter 2:
/ * strcat: concatenate t to end of s; s must be big enough * /
void strcat(char s[], char t[])
{
int i, j;
i = j = 0;
while (s[i] != '\0') / * find end of s * /
i++;
while ((s[i++] = t[j++]) != '\0') / * copy t * /
;
}
Author : Bryan Williams
*/
/* strcat: concatenate t to end of s; s must be big enough; pointer version */
void strcat(char *s, char *t)
{
/* run through the destination string until we point at the terminating '\0' */
while('\0' != *s)
{
++s;
}
/* now copy until we run out of string to copy */
while('\0' != (*s = *t))
{
++s;
++t;
}
}
#define DRIVER 6
#if DRIVER
#include <stdio.h>
int main(void)
{
char S1[8192] = "String One";
char S2[8192] = "String Two";
printf("String one is (%s)\n", S1);
printf("String two is (%s)\n", S2);
strcat(S1, S2);
printf("The combined string is (%s)\n", S1);
return 0;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?