字符指针作为函数参数

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

int my_strlen01(char*ch)

{

//计算字符串有效长度

  int i=0;  

  while(ch[i]!='')

  {

    i++;

  }

  return i;

}

int my_strlen(const chat*ch)

{

  char*temp=ch;

  while(*temp)temp++;

  return temp-ch;//两指针差就是有效长度

}

int main()

{

  char ch[]="hello world";

  int len=my_strlen(ch);

  printf("%d ",len);//11

  return EXIT_SUCCESS;

}

原文地址:https://www.cnblogs.com/wanghong19991213/p/13586619.html