#include<stdio.h>
#include<math.h>
#include<string.h>
//编写一函数len,求一个字符串的长度,注意该长度不计空格。
//要求用字符指针实现。在主函数中输入字符串,调用该len函数后输出其长度。
int len(char* sp)
{
int icount = 0;
while (*sp != '\0')
{
if (*sp != ' ')
{
icount++;
}
sp++;
}
return icount;
//实现sp所指串的长度,不计空格。
}
int main()
{
char ch[100];
gets(ch);
printf("%d", len(ch));
return 0;
}
ZZULIOJ1161: 字符串长度(指针专题)
最新推荐文章于 2021-12-15 10:08:40 发布