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://www.codercto.com/courses/l/17.html

查看所有标签

Getting Started with C++ Audio Programming for Game Development

Getting Started with C++ Audio Programming for Game Development

David Gouveia

Written specifically to help C++ developers add audio to their games from scratch, this book gives a clear introduction to the concepts and practical application of audio programming using the FMOD li......一起来看看 《Getting Started with C++ Audio Programming for Game Development》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具