/*----------------------------------------------------------------------------------------------------*/
#include <stdio.h> // Standard IO.
#include <conio.h> // Console. include getch().
/*----------------------------------------------------------------------------------------------------*/
void String_Copy(char *cp_src, char *cp_tgt)
{
while(*cp_src != 0)
{
*cp_tgt = *cp_src;
cp_tgt++;
cp_src++;
}
}
/*----------------------------------------------------------------------------------------------------*/
void main(void)
{
/****************************************************/
char c_src_str[11] = "GavinChang";
char c_tgt_str[11] = { 0 };
/****************************************************/
printf("Hello world !\n"); // Print a string.
/****************************************************/
printf("The source string :%s\n", c_src_str);
printf("The target string :%s\n", c_tgt_str);
String_Copy(c_src_str, c_tgt_str);
printf("The source string :%s\n", c_src_str);
printf("The target string :%s\n", c_tgt_str);
/****************************************************/
getch(); // Hold on the console window.
/****************************************************/
}
/*----------------------------------------------------------------------------------------------------*/
本文展示了一个使用C语言标准库实现字符串复制的简单程序,包括如何使用`String_Copy`函数复制源字符串到目标字符串,并在复制前后打印字符串。
467

被折叠的 条评论
为什么被折叠?



