TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <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>
|
|