当前位置: 查字典范文网 >> 2023年c语言中函数strlen通用

2023年c语言中函数strlen通用

格式:DOC 上传日期:2023-04-27 18:10:59
2023年c语言中函数strlen通用
时间:2023-04-27 18:10:59     小编:zdfb

人的记忆力会随着岁月的流逝而衰退,写作可以弥补记忆的不足,将曾经的人生经历和感悟记录下来,也便于保存一份美好的回忆。写范文的时候需要注意什么呢?有哪些格式需要注意呢?以下是我为大家搜集的优质范文,仅供参考,一起来看看吧

c语言中函数strlen篇一

c库提供了多个字符串处理函数,ansi c把这些函数的原型放在string.h头文件中。其中最常用的有strlen()、strcat()、strcmp()、strncmp()、strcpy()和strncpy()。另外还有sprintf(),其原型在stdio.h头文件中。下面一起来学习一下吧!

strlen()函数用于统计字符串的长度,它会统计字符包括空格和标点符号,不统计空字符。注意与sizeof运算符区分,sizeof以字节为单位返回运算对象(变量名、类型名等)的大小。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<code>

/* test_fit.c -- try the string-shrinking function */

#include <stdio.h>

#include <string.h>

/* contains string function prototypes */

void

fit(

char

*, unsigned

int

);

 

int

main(

void

)

{

    

char

mesg[] =

"things should be as simple as possible,"

    

" but not simpler."

;

 

    

puts(mesg);

    

fit(mesg,

38

);

    

puts(mesg);

    

puts(

"let's look at some more of the string."

);

    

puts(mesg +