求字符串的有效字符的个数
来源:互联网 发布:flash player mac版本 编辑:程序博客网 时间:2024/06/05 19:42
#include <stdio.h>
#include <string.h> //调用库函数strlen,
//求字符串的有效长度
int mystrlen(const char *src)
{
int count=0;
while(*src!=0)
{
count ++;
src++;
}
return count;
}
int main()
{
char str1[100] = "abcdef";
char *str2 = "abcdef";
char str3[] = "abcdef";
char str4[100] = "abcde\0fgh";
char str5[] = "abcde\0fgh";
char *str6 = "abcde\0fgh";
printf("%d,%d\n",sizeof(str1),strlen(str1));//100,6
printf("%d,%d\n",sizeof(str2),strlen(str2));//4,6
printf("%d,%d\n",sizeof(str2),mystrlen(str2));//4,6
printf("%d,%d\n",sizeof(str3),strlen(str3));//7,6
printf("%d,%d\n",sizeof(str4),strlen(str4));//100,5
printf("%d,%d\n",sizeof(str5),strlen(str5));//10,5
printf("%d,%d\n",sizeof(str6),strlen(str6));//4,5
printf("%d\n",strlen("*&^%43@! ][")); //11
printf("%d\n",mystrlen("*&^%43@! ][")); //11
printf("%d\n",mystrlen("56123dhkj")); //9
return 0;
}
#include <string.h> //调用库函数strlen,
//求字符串的有效长度
int mystrlen(const char *src)
{
int count=0;
while(*src!=0)
{
count ++;
src++;
}
return count;
}
int main()
{
char str1[100] = "abcdef";
char *str2 = "abcdef";
char str3[] = "abcdef";
char str4[100] = "abcde\0fgh";
char str5[] = "abcde\0fgh";
char *str6 = "abcde\0fgh";
printf("%d,%d\n",sizeof(str1),strlen(str1));//100,6
printf("%d,%d\n",sizeof(str2),strlen(str2));//4,6
printf("%d,%d\n",sizeof(str2),mystrlen(str2));//4,6
printf("%d,%d\n",sizeof(str3),strlen(str3));//7,6
printf("%d,%d\n",sizeof(str4),strlen(str4));//100,5
printf("%d,%d\n",sizeof(str5),strlen(str5));//10,5
printf("%d,%d\n",sizeof(str6),strlen(str6));//4,5
printf("%d\n",strlen("*&^%43@! ][")); //11
printf("%d\n",mystrlen("*&^%43@! ][")); //11
printf("%d\n",mystrlen("56123dhkj")); //9
return 0;
}
阅读全文
0 0
- 求字符串的有效字符的个数
- 求字符串的不同字符的个数
- 求一个字符串中字符总个数以及各个字符的个数
- 判断字符,字符串的个数
- 字符串中字符的个数
- 求给定字符串中包含的字符及个数及最多字符是哪个?
- 求字符串中英文字母,空格,数字,还有其他字符的个数
- 求字符串中满足所有字符个数相等的最长子串长度
- 求字符串中字符最多的字符
- [MSSQL]求字符串中汉字的个数
- 求字符串中单词的个数
- 求字符串中汉字的个数
- 求一个字符串中大写字母的个数
- 汇编求字符串中空格的个数
- 求字符串的子串个数
- JAVA 高效判断字符串的字符个数
- 统计字符串中各个字符的个数
- 统计字符串中相同字符的个数
- int型的数到底最大值是多少?
- study post
- 【数据结构】二叉树
- SpringBoot(八)SpringBoot整合springsession实现分布式session共享
- java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplemen
- 求字符串的有效字符的个数
- 团体程序设计天梯赛-练习集 L1-048. 矩阵A乘以B
- 在 SpringMVC 中对表单提交参数进行验证(使用 Bean Validator)
- 二元运算符重载
- 网络最大流
- Unsupported major.minor version 52.0
- UE4开启SkeletalMesh三角面碰撞失败(EnableperpolyCollision无效)
- oracle的in 和not in
- JAVA三个特性(封装,继承和多态)