C 语言实例 - 字符串复制
C 语言教程
· 2019-02-21 09:59:03
将一个变量的字符串复制到另外一个变量中。
实例 - 使用 strcpy()
#include <stdio.h>
#include <string.h>
int main()
{
char src[40];
char dest[100];
memset(dest, '\0', sizeof(dest));
strcpy(src, "This is codercto.com");
strcpy(dest, src);
printf("最终的目标字符串: %s\n", dest);
return(0);
}
输出结果为:
最终的目标字符串: This is codercto.com
实例 - 不使用 strcpy()
#include <stdio.h>
int main()
{
char s1[100], s2[100], i;
printf("字符串 s1: ");
scanf("%s",s1);
for(i = 0; s1[i] != '\0'; ++i)
{
s2[i] = s1[i];
}
s2[i] = '\0';
printf("字符串 s2: %s", s2);
return 0;
}
输出结果为:
字符串 s1: codercto 字符串 s2: codercto
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Rationality for Mortals
Gerd Gigerenzer / Oxford University Press, USA / 2008-05-02 / USD 65.00
Gerd Gigerenzer's influential work examines the rationality of individuals not from the perspective of logic or probability, but from the point of view of adaptation to the real world of human behavio......一起来看看 《Rationality for Mortals》 这本书的介绍吧!