17--2--6求字符串长度

来源:互联网 发布:怎么用服务器ip做域名 编辑:程序博客网 时间:2024/06/05 17:50
/** Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:纪丽娜* 完成日期:2013 年  12月* 版 本 号:v1.0* 问题描述:求字符串长度*/#include <iostream>using namespace std;int astrlen(char *str1);int main(){    char a[50]="Hello world";    char b[50]="Good moring";    int x,y;    x=astrlen(a);    cout<<"字符串长度为"<<x<<endl;    y=astrlen(b);    cout<<"字符串长度为"<<y<<endl;    return 0;}int astrlen(char *str1){    char *p;    int i=0;    for(p=str1;*p!='\0';p++)    {        i++;    }    return i;}

0 0
原创粉丝点击