当前位置:网站首页>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;
}
边栏推荐
- Detailed explanation of classic process synchronization problems
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
- Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- Mongodb vs mysql, which is more efficient
- 记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
- The most robust financial products in 2022
- BCD code Baidu Encyclopedia
- Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
- Lecture 9
- R语言--readr包读写数据
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
Detailed explanation of classic process synchronization problems
The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
Practical dry goods: deploy mini version message queue based on redis6.0
Servlet learning notes
Enter the smart Park, and change begins here
JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
Azure solution: how can third-party tools call azure blob storage to store data?
Clion configuration of opencv
随机推荐
Shift EC20 mode and switch
Haproxy cluster
template<typename MAP, typename LIST, typename First, typename ... Keytypes > recursive call with indefinite parameters - beauty of Pan China
It's hard to hear C language? Why don't you take a look at this (V) pointer
Force buckle 142 Circular linked list II
Fastlane 一键打包/发布APP - 使用记录及踩坑
Single spa, Qiankun, Friday access practice
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
Method of setting default items in C # ComboBox control code
LVS load balancing cluster deployment - Dr direct routing mode
Reptile learning 3 (winter vacation learning)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
A few words explain redis cache penetration, breakdown, avalanche, and redis sentinel
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
Recommend a cool geospatial data visualization tool with low code
03_ Armv8 instruction set introduction load and store instructions
2021-10-20
Introduction of network security research direction of Shanghai Jiaotong University
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22