当前位置:网站首页>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;
}
边栏推荐
- Openssl3.0 learning 20 provider KDF
- OSI seven layer model & unit
- . Does net 4 have a built-in JSON serializer / deserializer- Does . NET 4 have a built-in JSON serializer/deserializer?
- [ES6] template string: `string`, a new symbol in es2015
- Decrypt the advantages of low code and unlock efficient application development
- Global and Chinese market of cardiac monitoring 2022-2028: Research Report on technology, participants, trends, market size and share
- CSDN documentation specification
- Bottom Logic -- Mind Map
- 2021-10-20
- Unity performance optimization reading notes - Introduction (1)
猜你喜欢
Azure solution: how can third-party tools call azure blob storage to store data?
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
Day01 preliminary packet capture
OSI seven layer model & unit
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
Hongke case study on storm impact in coastal areas of North Carolina using lidar
01. Basics - MySQL overview
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
随机推荐
Btrace tells you how to debug online without restarting the JVM
World document to picture
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
Install freeradius3 in the latest version of openwrt
Reptile learning 3 (winter vacation learning)
Global and Chinese market of ice water machines 2022-2028: Research Report on technology, participants, trends, market size and share
How to create a new virtual machine
Introduction of network security research direction of Shanghai Jiaotong University
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
R语言--readr包读写数据
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
[directory] search
Number and math classes
Alibaba cloud server connection intranet operation
Foreach (system.out:: println) usage
13、 C window form technology and basic controls (3)
Bottom Logic -- Mind Map
2021 annual summary - it seems that I have done everything except studying hard