当前位置:网站首页>【指针】求字符串的长度
【指针】求字符串的长度
2022-07-06 09:24:00 【|光|】
要求
编一个函数,求字符串的长度。(用指针实现)
代码
/* * 该函数用来实现计算形参a所指向的字符串的长度 * 计算得到的字符串长度以函数值方式返回 * 注:不能使用系统库函数 */
int str_len(char *a)
{
int len=0;
for(int i=0;i<300;i++)
{
if(a[i]=='\0')
break;
else
len++;
}
return len;
}
main函数
int main()
{
char a[300];
int n;
gets(a);
n=str_len(a);
printf("%d\n",n);
return 0;
}
测试
测试输入
Those engraved in the chair behind the love, will not like the cement on the flowers, out of no wind, lonely forest.
输出
116
边栏推荐
- Hackmyvm Target Series (3) - vues
- Windows platform mongodb database installation
- flask实现强制登陆
- MySQL interview questions (4)
- 攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
- 《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
- Intranet information collection of Intranet penetration (I)
- 中间件漏洞复现—apache
- Network layer - simple ARP disconnection
- How to understand the difference between technical thinking and business thinking in Bi?
猜你喜欢
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
How to understand the difference between technical thinking and business thinking in Bi?
Low income from doing we media? 90% of people make mistakes in these three points
On the idea of vulnerability discovery
Realize applet payment function with applet cloud development (including source code)
《统计学》第八版贾俊平第二章课后习题及答案总结
Tencent map circle
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
Hackmyvm target series (3) -visions
captcha-killer验证码识别插件
随机推荐
Circular queue (C language)
记一次edu,SQL注入实战
A complete collection of papers on text recognition
Applet Web Capture -fiddler
Markdown font color editing teaching
小程序web抓包-fiddler
Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
浅谈漏洞发现思路
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
Data mining - a discussion on sample imbalance in classification problems
Xray and burp linkage mining
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
图书管理系统
xray與burp聯動 挖掘
Network layer - simple ARP disconnection
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
MSF generate payload Encyclopedia
Overview of LNMP architecture and construction of related services
7-9 make house number 3.0 (PTA program design)
关于交换a和b的值的四种方法