问题及代码:
/*。
*Copyright(c)2014,烟台大学计算机学院
*All right reserved,
*文件名:test.cpp
*作者:liu_feng_zi_
*完成日期:2014年12月16日
*版本号:v1.0
*
问题描述:输出字符长度
*输入描述:
*程序输出:
*/
#include <iostream>
using namespace std;
int pstrlen(char *str);
int main()
{
char s1[50]="Hello world. ";
char s2[50]="Good morning. ";
cout<<"s1的字符长度为:"<< pstrlen(s1)<<endl;
cout<<"s2的字符长度为:"<<pstrlen(s2)<<endl;
return 0;
}
int pstrlen(char *str)
{
int i=0;
while(*(str+i)!='\0')
{
i++;
}
return i;
}
运行结果: