当前位置:网站首页>C language programming -- input a string (including letters, numbers, punctuation marks, and space characters) from the keyboard, calculate the actual number of characters and print out, that is, it d
C language programming -- input a string (including letters, numbers, punctuation marks, and space characters) from the keyboard, calculate the actual number of characters and print out, that is, it d
2022-06-13 03:27:00 【Where is the continued prosperity】
Enter any string from the keyboard ( Can contain : Letter 、 Numbers 、 Punctuation , And space characters ), Calculate the actual number of characters and print out , That is, do not use string handlers strlen() Programming , But it can be achieved strlen() The function of .
Program running example :
Please enter a string:how are you
The length of the string is: 11
The procedure is as follows , The horizontal line represents the missing source code , Please add the missing part , And fill in the complete program code in the answer area .
#include <stdio.h>
___________ /* Function declaration */
int main()
{
char a[80];
unsigned int len;
printf("Please enter a string:");
___________ /* Input string */
___________ /* Call function , Calculate the actual number of characters in the string */
printf("The length of the string is: %u\n", len);
return 0;
}
/* The functionality : Use character pointer as function parameter , Calculate the length of the string */
unsigned int MyStrlen(char *pStr)
{
___________ /* Declare count variables */
for ( ______ ;_______ ;________) /* Cycle control conditions */
{
len++; /* Statistics do not include '\0' Number of characters included
}
___________ /* Returns the actual number of characters */
}The answer is as follows :
#include <stdio.h>
unsigned int MyStrlen(char *pStr);
int main()
{
char a[80];
unsigned int len;
printf("Please enter a string:");
gets(a);
len = MyStrlen(a);
printf("The length of the string is: %u\n", len);
return 0;
}
/* The functionality : Use character pointer as function parameter , Calculate the length of the string */
unsigned int MyStrlen(char *pStr)
{
unsigned int len = 0;
for ( ; *pStr!='\0'; pStr++)
{
len++;
}
return (len);
} 边栏推荐
- 技术博客,经验分享宝典
- 开源-校园论坛和资源共享小程序
- Personal understanding of grammar sugar
- Environmental pollution, enterprises, highways, fixed assets, foreign investment in all prefecture level cities in China - latest panel data
- [JVM series 8] overview of JVM knowledge points
- C# . NET ASP. Net relationships and differences
- 最近最少使用缓存(来源力扣)
- A personal understanding of interpreted and compiled languages
- Four ways of array traversal in PHP
- Age anxiety? How to view the 35 year old programmer career crisis?
猜你喜欢

Summary of virtualization technology development

Azure SQL db/dw series (14) -- using query store (3) -- common scenarios

Azure SQL db/dw series (9) -- re understanding the query store (2) -- working principle

Technology blog, a treasure trove of experience sharing

Nuggets new oil: financial knowledge map data modeling and actual sharing

Typical application of ACL

开源-校园论坛和资源共享小程序
![[azure data platform] ETL tool (7) - detailed explanation of ADF copy data](/img/d1/7c35e77a2b4f06dd9cef918da1104e.jpg)
[azure data platform] ETL tool (7) - detailed explanation of ADF copy data

Summary of rust language practice

Environmental pollution, enterprises, highways, fixed assets, foreign investment in all prefecture level cities in China - latest panel data
随机推荐
Unified scheduling and management of dataX tasks through web ETL
Time processing class in PHP
2000-2019 enterprise registration data of provinces, cities and counties in China (including longitude and latitude, number of registrations and other multi indicator information)
(九)详解广播机制
Complex network analysis capability based on graph database
MySQL group commit
Several functions in YAF framework controller
Simple use of qtreeview of QT (including source code + comments)
Review notes of RS data communication foundation STP
Four ways of array traversal in PHP
How to write product requirements documents
A personal understanding of interpreted and compiled languages
Radium laser radar C16 data to PCD (based on ROS)
[azure data platform] ETL tool (8) - ADF dataset and link service
Azure SQL db/dw series (11) -- re understanding the query store (4) -- Query store maintenance
Capital digit to number format
Qt之QTreeView的简单使用(含源码+注释)
Common command records of redis client
The use of curl in PHP
Masa auth - SSO and identity design