通过strlen()方法和循环遍历分别获取指针指向的字符串长度
2013-03-08 10:48
537 查看
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(){
char *c="licheng";
//使用strlen()方法获取指针指向的字符串长度
printf("字符长度为(strlen方法):%d\n",strlen(c));
//通过遍历获取字符串长度
int num = 0;
while(*c){
printf("%c",*c);
c++;
num++;
}
printf("字符长度为(遍历):%d\n",num);
system("pause");
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(){
char *c="licheng";
//使用strlen()方法获取指针指向的字符串长度
printf("字符长度为(strlen方法):%d\n",strlen(c));
//通过遍历获取字符串长度
int num = 0;
while(*c){
printf("%c",*c);
c++;
num++;
}
printf("字符长度为(遍历):%d\n",num);
system("pause");
}
相关文章推荐
- 测试了3种获取中英文混合字符串长度的方法,看来还是使用循环来的快
- 用指针的方法,将字符串“ABCD1234efgh”前后对调显示//不要用strlen求字符串长度,这样就没分了
- 指针指向的字符数组长度的获取方法
- shell中获取字符串长度的方法,获取数组元素个数,获取数组元素,数组遍历
- 通过js来获取包含中文字符的字符串的长度的方法
- 获取动态数组指针 所指向数组长度的一种方法
- 通过js来获取包含中文字符的字符串的长度的方法
- PHP获取字符串长度之strlen和mb_strlen的区别
- 获取英汉混合字符串的长度 mb_strlen
- strlen、ord、substr函数——获取长度、ASCII码及部分字符串
- js 获取字符串长度方法length
- 用指向指针方法对N个字符串进行排序并输出
- C#实现 获取指定字节长度 中英文混合字符串 的方法
- jquery之each循环遍历的方法---split 分割字符串返回数组
- 不能通过键盘输入一个字符串,并使未初始化的指针指向它
- string方法 PadLeft 返回一个新字符串,该字符串通过在此实例中的字符左侧填充指定的 Unicode 字符来达到指定的总长度,从而使这些字符右对齐。 PadRight 右边
- C#实现 获取指定字节长度 中英文混合字符串 的方法
- 假设在长度大于1的循环链表中,即无头结点也无头指针,s为指向链表中的某个结点的指针,试编写算法删除结点s的前驱结点
- 获取字符串的长度(strlen/length)
- C#实现 获取指定字节长度 中英文混合字符串 的方法