滴水逆向联盟
标题:
基于visual Studio2013解决C语言竞赛题之0704字符串长度
[打印本页]
作者:
大灰狼
时间:
2014-9-12 08:49
标题:
基于visual Studio2013解决C语言竞赛题之0704字符串长度
题目
download.png
(13.35 KB, 下载次数: 926)
下载附件
保存到相册
2014-9-12 08:49 上传
解决代码及点评
<pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/************************************************************************/
/*
4、 写一函数,求一个字符串的长度。在main函数中输入字符串,并输出其长度。
*/
/************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int MyLenthA4(char * p)
{
int num=0;
if (p==NULL)
{
return 0; // 空串返回0
}
else
{
while(*p!='\0') // 用while循环计数
{
num++;
p++;
}
}
return num;
}
void main()
{
char p[]="sadhghasdwlg";
printf(" 字符串长度为%d",MyLenthA4(p));
system("pause");
}</pre><br><br></pre></pre>
欢迎光临 滴水逆向联盟 (http://www.dtdebug.com/)
Powered by Discuz! X3.2