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

C语言实现动态字符串,并且统计大小写

2016-06-08 17:06 435 查看
#include<stdio.h>

int main(int argc, char * argv[])
{
char *p;
char str[100];
int n=10;
int len;
int count_upper=0;
int count_lower=0;
int count_num=0;
printf("input string:\n");
p=(char*)malloc(sizeof(char)*n);
gets(str);
len=strlen(str)+1;
if(len>n)
{
p=(char*)realloc(p,sizeof(char)*len);
}
strcat(p,str);
printf("%s\n",p);
while(*p!=NULL)
{
if(*p>=65 && *p<=90)
{
count_upper+=1;
}
if(*p>=97 && *p<=122)
{
count_lower+=1;
}
*p++;
}

printf("%d\n",count_lower);
printf("%d\n",count_upper);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: