当前位置:网站首页>C语言程序设计——从键盘任意输入一个字符串,计算其实际字符个数并打印输出,要求不能使用字符串处理函数strlen(),使用自定义子函数Mystrlen()实现计算字符个数的功能。
C语言程序设计——从键盘任意输入一个字符串,计算其实际字符个数并打印输出,要求不能使用字符串处理函数strlen(),使用自定义子函数Mystrlen()实现计算字符个数的功能。
2022-06-13 03:23:00 【续繁华又何处】
从键盘任意输入一个字符串,计算其实际字符个数并打印输出,要求不能使用字符串处理函数strlen(),使用自定义子函数Mystrlen()实现计算字符个数的功能。
函数原型:int MyStrlen(char str[])
函数功能:计算存放在字符数组str[]中的字符串的实际字符个数(即不包括'/0')
输入提示信息:"Please enter a string:"
输入格式要求:用gets()函数
输出格式要求:"The length of the string is: %d\n"
程序的运行示例1:
Please enter a string:Hello China
The length of the string is: 11代码如下:
#include <stdio.h>
int MyStrlen(char str[]);
int MyStrlen(char str[])
{
int i ;
int len = 0;
for (i = 0; str[i] != '\0'; i++)
{
len++;
}
return (len);
}
int main()
{
char a[80];
int len;
printf("Please enter a string:");
gets(a);
len = MyStrlen(a);
printf("The length of the string is: %d\n", len);
return 0;
} 边栏推荐
- Vs 2022 new features_ What's new in visual studio2022
- Parallel one degree relation query
- Spoon database insert table operation
- Differences between XAML and XML
- C# . NET ASP. Net relationships and differences
- Understanding of intermediatelayergetter
- Polymorphism in golang
- Understanding the ongdb open source map data foundation from the development of MariaDB
- PostgreSQL common SQL
- C 10 new features_ C 10 new features
猜你喜欢
![Loading process of [JVM series 3] classes](/img/a7/707c5cb95de71d95bf6ad9b2f69afa.jpg)
Loading process of [JVM series 3] classes

Keil removes annoying st link update tips

Microservice practice based on rustlang

【pytorch 记录】pytorch的变量parameter、buffer。self.register_buffer()、self.register_parameter()

Neil eifrem, CEO of neo4j, interprets the chart data platform and leads the development of database in the next decade
![[JVM series 4] common JVM commands](/img/32/339bf8a2679ca37a285f345ab50f00.jpg)
[JVM series 4] common JVM commands

Introduction to redis (using redis, common commands, persistence methods, and cluster operations)

MySQL 8.0 installation free configuration method

技术博客,经验分享宝典

Wechat applet coordinate location interface usage (II) map interface
随机推荐
Four ways of array traversal in PHP
Parallel one degree relation query
Least recently used cache (source force deduction)
开源-校园论坛和资源共享小程序
MySQL index bottom layer (I)
A data modeling optimization solution for graph data super nodes
Redis memory optimization and distributed locking
Reading notes of effective managers
Spoon database insert table operation
Azure SQL db/dw series (9) -- re understanding the query store (2) -- working principle
MySQL imports and exports multiple libraries at one time
English grammar_ Mode adverb position
Azure SQL db/dw series (10) -- re understanding the query store (3) -- configuring the query store
技术博客,经验分享宝典
Filters in PHP
Patrick Pichette, partner of inovia, former chief financial officer of Google and current chairman of twitter, joined the board of directors of neo4j
brew工具-“fatal: Could not resolve HEAD to a revision”错误解决
MySQL index optimization (4)
C# . NET ASP. Net relationships and differences
Array in PHP array function_ Slice and array_ flip