1. 编程学习网 > 编程教程 > C语言教程 > C语言100道经典题目70

C语言100道经典题目70

C 语言经典100例

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

程序分析:无。

实例

// #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.itjx.com
字符串有 12 个字符。

本文由IT教学网整理发布,转载请注明出处:http://www.clang.cc//jiaocheng/cyuyan/1244.html

联系我们

在线咨询:点击这里给我发消息

咨询电话:400-998-2681

工作时间:7*24小时无休