Chinaunix首页 | 论坛 | 博客
  • 博客访问: 242341
  • 博文数量: 88
  • 博客积分: 1429
  • 博客等级:
  • 技术积分: 523
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-18 15:31
文章分类

全部博文(88)

文章存档

2017年(2)

2016年(24)

2013年(1)

2012年(24)

2011年(15)

2010年(22)

我的朋友

分类: WINDOWS

2010-10-21 18:47:04

#include <assert.h>
#include <stdio.h>

int mystrlen(const char *str)
{
    assert(str != NULL);
    return ('\0' != *str) ? (mystrlen(str + 1) + 1) : 0;
}

void main()
{
    char *buf = "abcdefghij";
    printf("The length of %s is: %d", buf, mystrlen(buf));
}


 

/*
 * assert prints a diagnostic message when expression evaluates to false (0)
 * and calls abort to terminate program execution.
 * No action is taken if expression is true (nonzero).
 * The diagnostic message includes the failed expression
 * and the name of the source file and line number where the assertion failed.
 */


阅读(667) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~