当前位置:网站首页>【指针】求字符串的长度
【指针】求字符串的长度
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
边栏推荐
- xray与burp联动 挖掘
- 攻防世界MISC练习区(gif 掀桌子 ext3 )
- servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
- 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
- Intel oneapi - opening a new era of heterogeneity
- 《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
- 7-14 error ticket (PTA program design)
- Low income from doing we media? 90% of people make mistakes in these three points
- SQL注入
- How to earn the first pot of gold in CSDN (we are all creators)
猜你喜欢
ES全文索引
Circular queue (C language)
Record an edu, SQL injection practice
记一次edu,SQL注入实战
Build domain environment (win)
Intranet information collection of Intranet penetration (4)
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
xray与burp联动 挖掘
JDBC看这篇就够了
Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
随机推荐
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
DVWA (5th week)
Library management system
Hackmyvm target series (3) -visions
《统计学》第八版贾俊平第一章课后习题及答案总结
网络基础之路由详解
Data mining - a discussion on sample imbalance in classification problems
Intranet information collection of Intranet penetration (5)
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
《统计学》第八版贾俊平第四章总结及课后习题答案
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
记一次edu,SQL注入实战
HackMyvm靶機系列(3)-visions
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
[issue 18] share a Netease go experience
Circular queue (C language)
内网渗透之内网信息收集(二)
Detailed explanation of network foundation routing