练习:<string.h>常用字符串

/*#include <string.h>

1、strlen 计算字符串长度;

2、strcop 拷贝;

3、strncop 拷贝指定数量的字符;

4、shrcat 连接字符串;*/

#include <stdio.h>
#include <string.h>
int main(void)
{
 char a[64];
 int k;
 printf("请输入一个字符串:");
 gets(a);
 k = strlen(a);
 printf("字符串长度是:%d\n",k);
 return 0;
}

#include <stdio.h>
#include <string.h>
int main(void)
{
 char a[64] = "love";
 char b[64] = "thinks";
 //strcop的第一个参数,是目标字符串;
 //strcop的第二个参数,是源字符串;
 strcpy(a,b);
 printf("输出结果:%s\n",a);
 
 return 0;
}

扫描二维码关注公众号,回复: 4857528 查看本文章

#include <stdio.h>
#include <string.h>
int main(void)
{
 char a[64] = "love";
 char b[64] = "123456";
 //strcop的第一个参数,是目标字符串;
 //strcop的第二个参数,是源字符串;
 strncpy(a,b,3); //strncpy函数是拷贝指定数量的字符串;
 printf("输出结果:%s\n",a);
 
 return 0;
}

#include <stdio.h>
#include <string.h>
int main(void)
{
 char a[64];
 char b[64];
 printf("输入一个字符:");
 gets(a);
 printf("输入一个字符:");
 gets(b);
 strcat(a,b); //strcat是连接字符串
 printf("输出结果:%s\n",a);
 return 0;
}

猜你喜欢

转载自www.cnblogs.com/fzhiyaoy/p/10249656.html