閱讀396 返回首頁    go 阿裏雲 go 技術社區[雲棲]


計算unsigned short*字符串長度

函數實現:
/*
 *函 數 名:wuslen
 *功    能:計算unsigned short*字符串長度
 *輸入參數:str unsigned short*字符串
 *輸出參數:無
 *返 回 值:unsigned short*字符串
 */  
int wuslen(const unsigned short* str) 
{ 
  int i=0; 

  if(str == NULL)
    return i;  
  
  while(str[i])
  {
   i++;
  } 
  
  return i; 
} 


實例:

#include <stdio.h>

int wuslen(const unsigned short* str) 
{ 
  int i=0; 

  if(str == NULL)
    return i;  
  
  while(str[i])
  {
   i++;
  } 
  
  return i; 
} 



int main()
{
  unsigned short str[] ={0x01,0x02,0x03,0x00};
  
  int len = wuslen(str);

  printf("len:%d\n",len);

  return 0;

}


最後更新:2017-04-02 06:52:03

  上一篇:go Socket PrintWriter 中 write() 與 print() 的區別
  下一篇:go htonl(),htons(),ntohl(),ntons()--大小端模式轉換函數