17--2--15先自己输入字符串再求长度

来源:互联网 发布:三维坐标测量仪软件 编辑:程序博客网 时间:2024/05/20 19:49
/** Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:纪丽娜* 完成日期:2013 年  12月* 版 本 号:v1.0* 问题描述:先自己输入字符串在求长度!*/#include <iostream>using namespace std;int main(){    int length(char *p);    int len;    char str[20];    cout<<"input string:";    cin>>str;    len=length(str);    cout<<"The lendth of string is "<<len<<"."<<endl;    return 0;}int length(char *p){    int n=0;    while(*p!='\0')    {        n++;        p++;    }    return n;}

0 0
原创粉丝点击