关于指针的问题?

lvjt86 2008-11-15 01:33:08
用指针编写一个程序,当输入一个字符串(用键盘输入)后,要求不仅能够统计其中字符的个数,还能指出其中大、小写字母、数字以及其他字符的个数。
...全文
100 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nullah 2008-11-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hqin6 的回复:]
C/C++ code#include <stdio.h>
#include<stdlib.h>

void fun(const char* p)
{
int count=0, num=0,ABC=0,abc=0,other=0;
printf(p);
printf("\n");
while(*p!='\0')
{
if(*p>='0'&& *p<='9')
num++;
else if(*p>='a' && *p<='z')
abc++;
else if(*p>='A' && *p<='Z')
ABC++;
else
other++;

[/Quote]
UP
lvjt86 2008-11-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 lvjt86 的帖子:]
用指针编写一个程序,当输入一个字符串(用键盘输入)后,要求不仅能够统计其中字符的个数,还能指出其中大、小写字母、数字以及其他字符的个数。
[/Quote]
用动态数组分配内存
太乙 2008-11-15
  • 打赏
  • 举报
回复
#include <stdio.h> 
#include<stdlib.h>

void fun(const char* p)
{
int count=0, num=0,ABC=0,abc=0,other=0;
printf(p);
printf("\n");
while(*p!='\0')
{
if(*p>='0'&& *p<='9')
num++;
else if(*p>='a' && *p<='z')
abc++;
else if(*p>='A' && *p<='Z')
ABC++;
else
other++;
count++;
p++;
}
printf("总共:%d,数字:%d,小写:%d,大写:%d,其他:%d\n",count,num,abc,ABC,other);
}

int main()
{
fun("helofdJKFDJSK32423 3 $#$#%");
}
帅得不敢出门 2008-11-15
  • 打赏
  • 举报
回复

int main()
{
char str[100],*p;
int num[4],i;
p=str;
gets(str);
for(i=0;i<4;i++)
num[i]=0;
for(;*p!='\0';p++)
{
if((*p<='z'&&*p>='a')||(*p<='Z'&&*p>='A')) num[0]++;
else if(*p==' ') num[1]++;
else if((*p<='9'&&*p>='0')) num[2]++;
else num[3]++;
}
printf("%d %d %d %d\n",num[0],num[1],num[2],num[3]);
return 0;
}

太乙 2008-11-15
  • 打赏
  • 举报
回复
#include <stdio.h> 
#include<stdlib.h>

void fun(const char* p)
{
int count=0, num=0,ABC=0,abc=0,other=0;
while(*p!='\0')
{
if(*p>='0'&& *p<='9')
num++;
else if(*p>='a' && *p<='z')
abc++;
else if(*p>='A' && *p<='Z')
ABC++;
else
other++;
count++;
p++;
}
printf("总共:%d,数字:%d,小写:%d,大写:%d,其他:%d\n",count,num,abc,ABC,other);
}

int main()
{
fun("helofdJKFDJSK32423 3 $#$#%");
}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧