当前位置:网站首页>C语言:求字符串的长度
C语言:求字符串的长度
2022-07-04 12:32:00 【念迟鱼学编程】
问题:
写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
代码
#include <stdio.h>
#include <stdlib.h>
int length(char *s)
{
int i = 0;
while(*s != '\0'){
i++;
s++;
}
return 1;
}
int main()
{
int len;
char str[20];
printf("请输入字符串:\n");
scanf("%s",str);
len = length(str);
printf("字符串有%d个字符。\n",len);
return 0;
}
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
- PKCs 5: password based cryptography specification version 2.1 Chinese Translation
- asp. Core is compatible with both JWT authentication and cookies authentication
- Method of setting default items in C # ComboBox control code
- Number and math classes
- How to use "bottom logic" to see the cards in the world?
- Anti clockwise rotation method of event arrangement -- PHP implementation
- Kivy教程之 08 倒计时App实现timer调用(教程含源码)
- Reptile learning winter vacation series (2)
- Using terminal connection in different modes of virtual machine
猜你喜欢
![Entitas learning [3] multi context system](/img/f9/a3ce86ff2121dd1043305b7e834cc5.jpg)
Entitas learning [3] multi context system

Detailed explanation of classic process synchronization problems

Games101 Lesson 8 shading 2 Notes

Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography

netstat

Reptile learning 4 winter vacation series (3)

Some summaries of the 21st postgraduate entrance examination 823 of network security major of Shanghai Jiaotong University and ideas on how to prepare for the 22nd postgraduate entrance examination pr
![[notes] in depth explanation of assets, resources and assetbundles](/img/e9/ae401b45743ea65986ae01b54e3593.jpg)
[notes] in depth explanation of assets, resources and assetbundles

Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)

The database connection code determines whether the account password is correct, but the correct account password always jumps to the failure page with wrong account password
随机推荐
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
Source code analysis of the implementation mechanism of multisets in guava class library
LxC shared directory addition and deletion
VBA, JSON interpretation, table structure -json string conversion
Entitas learning [iv] other common knowledge points
French Data Protection Agency: using Google Analytics or violating gdpr
13、 C window form technology and basic controls (3)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
Map container
Single spa, Qiankun, Friday access practice
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
Global and Chinese market of cardiac monitoring 2022-2028: Research Report on technology, participants, trends, market size and share
How do std:: function and function pointer assign values to each other
Global and Chinese market of piston rod 2022-2028: Research Report on technology, participants, trends, market size and share
Introduction to random and threadlocalrandom analysis
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
About the use of URL, href, SRC attributes
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
Force buckle 142 Circular linked list II