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);
}
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);
}
相关文章推荐
- Rotate Array
- C语言通过串口发送AT指令
- C++ vector【基础】
- C/C++开发者必不可少的15款编译器+IDE
- 【心酸历程】atom上打造C/C++的ide
- C++中引用和匿名对象的理解和本质剖析
- C++ 引用外部 DLL
- 什么是预编译?何时需要预编译 (C、C++工程师面试题)
- Android之JNI NDK错误 c/c++ indexer has encountered a problem, An internal error occurred during xx
- 定义、声明、初始化、赋值 小记(C++)
- 图的最小生成树 Prim算法 C++实现
- c++中赋值与初始赋值的区别
- C++的Json解析库:jsoncpp和boost
- C/C++ 中static的常见作用
- Reverse Bits
- C++程序设计语言练习6.17 itoa 的实现
- C++文件操作详解
- C/C++ --- double与string的相互转化
- 29. Divide Two Integers
- C++走向远洋——66(十五周阅读程序)