不使用库函数,求一个字符串长度

/*
编写一个函数,不使用strlen等库函数,求得一个字符串的长度,参数为该字符串,返回值为该字符串的长度。
*/
#include "stdafx.h"
#include"stdlib.h"

int ves1(char num[]) {
    int a = 0, i = 0;
    while (num[i] != '\0')
    {
        a++;
        i++;
    }
    return a;

}
int main()
{    
    char ch[] = "fs46546";
    int h =ves1(ch);
    printf("字符串长度为:%d", h);
    system("pause");
    return 0;
}

 

posted @ 2017-01-19 15:32  WonderfulWorld  阅读(1108)  评论(0)    收藏  举报