C 语言实例 - 计算字符串长度
C 语言教程
· 2019-02-21 09:12:27
计算字符串长度。
实例 - 使用 strlen()
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000];
int len;
printf("输入字符串: ");
scanf("%s", s);
len = strlen(s);
printf("字符串长度: %d", len);
return 0;
}
输出结果为:
输入字符串: codercto 字符串长度: 6
实例 - 不使用 strlen()
#include <stdio.h>
int main()
{
char s[1000], i;
printf("输入字符串: ");
scanf("%s", s);
for(i = 0; s[i] != '\0'; ++i);
printf("字符串长度: %d", i);
return 0;
}
输出结果为:
输入字符串: codercto 字符串长度: 6
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Python Cookbook
Alex Martelli、Anna Ravenscroft、David Ascher / 高铁军 / 人民邮电出版社 / 2010-5-1 / 99.00元
本书介绍了Python应用在各个领域中的一些使用技巧和方法,从最基本的字符、文件序列、字典和排序,到进阶的面向对象编程、数据库和数据持久化、 XML处理和Web编程,再到比较高级和抽象的描述符、装饰器、元类、迭代器和生成器,均有涉及。书中还介绍了一些第三方包和库的使用,包括 Twisted、GIL、PyWin32等。本书覆盖了Python应用中的很多常见问题,并提出了通用的解决方案。书中的代码和方......一起来看看 《Python Cookbook》 这本书的介绍吧!