不使用中间变量实现字符串长度函数strlen

具体题目是不使用中间变量实现strlen函数,(strlen为c语言里面求字符串长度库函数)。

给出了一个函数声明:

int strlen(const char *p);

 

虽然我没有参加,但是听人家这么说起这个题目,呵呵方便大家看看!

这里给出我的实现,希望高手指点!

  1. int strlen_my(const char *p);
  2. int main(){ 
  3.     const char *p  = "ok!";
  4.     int a = strlen_my(p);
  5. int strlen_my(const char *p) {
  6.     if (p==NULL)
  7.     {
  8.         return 0;
  9.     }
  10.     if (*p == '/0')
  11.     {
  12.         return 0;
  13.     }
  14.     else 
  15.         return 1+strlen_my(++p);
  16. }

呵呵,腾讯居然不给我笔试机会,哎,水平太垃圾了,投哪个公司人家受笔试,我受鄙视!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章