字符串常用函数(1)
1.strlen函数
include <stdio.h>
int main()
{
//计算字符数组和字符串的长度('\0'的差别)
printf("%d %d",sizeof(str1),strlen(str1));
}
2.strcpy函数
include <stdio.h>
int main()
{
char *p="12345";
char a[20];
strcpy(a,p);
//地址p的字符串赋给a
且其有返回值,返回值为复制的字符串
}
strcpy_s安全函数和strcpy一样
但是参数有(被赋指针,字符串长度,赋予指针)
3.strncpy函数——部分拷贝
include <stdio.h>
int main()
{
char *p="12345";
char a[20];
strcpy(a,p.3);
//a字符串只保留p中前三个字符
//同样其也有安全函数
}
查看7道真题和解析
海康威视公司福利 1325人发布