#include
void count(char *s, int *a, int *b)
{
*a = *b = 0;
while(*s)
{
if('A' <= *s && *s <= 'Z' || 'a' <= *s && *s <= 'z')
(*a)++;
else
(*b)++;
s++;
}
}
int main()
{
char s[100];
int zm, qt;
printf("输入字符串:\n");
gets(s);
count(s, &zm, &qt);
printf("字母:%d\n", zm);
printf("其它:%d\n", qt);
return 0;
}
没有测试,你试一下对不对。应该是这样的
#include
#include
int letter;
void count(char str[]);
main()
{
char str[100];
letter=0;
printf("请输入一个字符串:\n");
gets(str);
count(str);
printf("输入字符串英文字母个数为%d\n",letter);
}
void count(char str[])
{
int i;
for(i=0;iif(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
letter++;
}
#include
#include
#include
#define BUFSIZE 4096
int alpha_count(char *s) {
int count = 0;
char *s1 = s;
while(*s1 != '\0') {
if(isalpha((int)*s1)){
count++;
}
s1++;
}
return count;
}
int main(void) {
char buf[BUFSIZE];
while(1){
printf("input any string:\n");
fgets(buf,sizeof(buf),stdin);
printf("alpha count %d\n\n",alpha_count(buf));
}
exit(0);
}
oracle中实现:
select tt.aa,length(regexp_replace(tt.aa,'[^[:alpha:]]*','')) from (select 'as222dc123ffggff ' as aa from dual) tt;
在C语言中,同样使用正则表达式将非中英文字母替换成空字符串,再求个数
int GetSum(char *str)
{
int count=0;
for(int i=0;str[i]!='\0';i++)
{
if((str[i]>='a' && str[i]<='z')||(str[i]>='A' && str[i]<='Z'))
count++;
}
return count;
}