C语言程序设计_数组_4.ppt.ppt

C语言程序设计_数组_4.ppt.ppt

C语言程序设计——;;知识回顾;char c[10]={’I’,’ ’,’a’,’m’,’ ’,’h’,’a’,’p’,’p’,’y’}; char c[ ]=“I am happy”;;字符数组常用操作;字符数组应用;在C函数库中提供了一些用来专门处理字符串的函数。 这些函数所在的库文件为: string.h;1. strlen函数----测字符串长度的函数 其一般形式为: strlen (字符数组) 它是测试字符串长度的函数 函数的值为字符串中的实际长度;1. strlen函数----测字符串长度的函数 char str[10]=”China”; printf(”%d”,strlen(str)); 输出结果是5 也可以直接测试字符串常量的长度 strlen(”China”);;2. strcat函数----字符串连接函数 其一般形式为: strcat(字符数组1,字符数组2) 其作用是把两个字符串连接起来,把字符串2接到字符串1的后面,结果放在字符数组1中;2. strcat函数----字符串连接函数 char str1[30]=”People”; char str2[]=”China”; printf(”%s”, strcat(str1,str2)); 输出:PeopleChina;3

文档评论(0)

1亿VIP精品文档

相关文档