C 练习实例70

C 语言教程 · 2019-02-22 11:29:33

题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。

程序分析:无。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include <stdio.h> #include <stdlib.h> int main() { int len; char str[20]; printf("请输入字符串:\n"); scanf("%s",str); len=length(str); printf("字符串有 %d 个字符。",len); } //求字符串长度 int length(char *s) { int i=0; while(*s!='\0') { i++; s++; } return i; }

以上程序执行输出结果为:

请输入字符串:
www.codercto.com
字符串有 14 个字符。

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Effective Java

Effective Java

Joshua Bloch / Addison-Wesley Professional / 2018-1-6 / USD 54.99

The Definitive Guide to Java Platform Best Practices—Updated for Java 9 Java has changed dramatically since the previous edition of Effective Java was published shortly after the release of Jav......一起来看看 《Effective Java》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码