C语言的字符串处理-长度(23)

来源:互联网 发布:韩国学术造假事件 知乎 编辑:程序博客网 时间:2024/05/10 05:21

 C语言的字符串处理-长度:

1  传递数组使用其名称即可

2  const的使用。防止修改。

/************************************************************
 Copyright (C), 1998-2006, Rx. Co., Ltd.
 FileName: mainApp.cpp
 Author: longronglin
 Version : 1.0
 Date: 2006-10-06
 Description:      
 Function List:   
    1. int main()
 History:      
      <author> <time> <version > <desc>
      longronglin    2006/10/06     1.0      modify xxx . 
**********************************************************
*/


#include 
<stdio.h>

//const 的妙用
int strlenTest(const char *string

    
int i=0
        //string 指针下移 其实就是读出字符 比如是h e l等。看是否为空。string[1]='h'等。
    
while(string[i]) 
    
{
           printf("%c", string[i]);
        i
++
    }

    
    
return i; 
}
 

/*
 * 返回1为正确执行
 * 主函数
 *
 
*/


int main()
{
    
char ch[] = "hello";
    
int len;
   
        //传递数组使用其名称即可
    len 
= strlenTest(ch);
    printf(
"%d", len);

    
return (1);
}
  
原创粉丝点击