当前位置:网站首页>C语言程序设计——从键盘任意输入一个字符串(可以包含:字母、数字、标点符号,以及空格字符),计算其实际字符个数并打印输出,即不使用字符串处理函数strlen()编程,但能实现strlen()的功能。
C语言程序设计——从键盘任意输入一个字符串(可以包含:字母、数字、标点符号,以及空格字符),计算其实际字符个数并打印输出,即不使用字符串处理函数strlen()编程,但能实现strlen()的功能。
2022-06-13 03:23:00 【续繁华又何处】
从键盘任意输入一个字符串(可以包含:字母、数字、标点符号,以及空格字符),计算其实际字符个数并打印输出,即不使用字符串处理函数strlen()编程,但能实现strlen()的功能。 程序运行示例: Please enter a string:how are you The length of the string is: 11 程序如下,横线处代表有缺失的源代码,请补充缺少的部分,并将完整的程序代码填写在答题区。 #include <stdio.h> ___________ /* 函数声明 */ int main() { char a[80]; unsigned int len; printf("Please enter a string:"); ___________ /* 输入字符串 */ ___________ /* 调用函数,计算字符串实际字符个数 */ printf("The length of the string is: %u\n", len); return 0; } /* 函数功能:用字符指针作函数参数,计算字符串的长度 */ unsigned int MyStrlen(char *pStr) { ___________ /* 声明计数变量 */ for ( ______ ;_______ ;________) /* 循环控制条件 */ { len++; /* 统计不包括'\0'在内的字符个数 } ___________ /* 返回实际字符个数 */ }
答案如下:
#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;
}
/* 函数功能:用字符指针作函数参数,计算字符串的长度 */
unsigned int MyStrlen(char *pStr)
{
unsigned int len = 0;
for ( ; *pStr!='\0'; pStr++)
{
len++;
}
return (len);
}
边栏推荐
- MySQL group commit
- Transaction processing in PDO
- Installing the IK word breaker
- Differences between XAML and XML
- Wechat applet coordinate location interface usage (II) map interface
- Beginner development process_ Project development FAQs
- Azure SQL db/dw series (10) -- re understanding the query store (3) -- configuring the query store
- Array in PHP array function_ Slice and array_ flip
- Explode and implode in PHP
- Use of interceptors webmvcconfigurer
猜你喜欢
Available types in C #_ Unavailable type_ C double question mark_ C question mark point_ C null is not equal to
JVM GC (V)
Alibaba cloud OSS access notes
【 enregistrement pytorch】 paramètre et tampon des variables pytorch. Self. Register Buffer (), self. Register Paramètre ()
Introduction to redis (using redis, common commands, persistence methods, and cluster operations)
2021-08-30 distributed cluster
Brew tool - "fatal: could not resolve head to a revision" error resolution
[figure data] how long does it take for the equity network to penetrate 1000 layers?
C simple understanding - generics
How to Draw Useful Technical Architecture Diagrams
随机推荐
【pytorch 记录】pytorch的变量parameter、buffer。self.register_buffer()、self.register_parameter()
JMeter quick start
Summary of virtualization technology development
[JVM Series 5] performance testing tool
JVM GC (V)
Three ways to start WPF project
Use of compact, extract and list functions in PHP
Technology blog, a treasure trove of experience sharing
C method parameter: params
This article takes you to learn DDD, basic introduction
视频播放屡破1000W+,在快手如何利用二次元打造爆款
Array in PHP array function_ Slice and array_ flip
Use and arrangement of wechat applet coordinate position interface (I)
MMAP usage in golang
Coordinate location interface of wechat applet (II) map plug-in
Pytorch record: pytorch variables parameter and buffer. self. register_ buffer()、self. register_ parameter()
Use of interceptors webmvcconfigurer
Age anxiety? How to view the 35 year old programmer career crisis?
C 10 new features_ C 10 new features
最近最少使用缓存(来源力扣)