您的位置:首页 > 编程语言 > C语言/C++

通过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");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐