编写一个函数,统计一个字符串中字母、数字和空格的个数。使用全局变量存放字母和数字个数,函数返回值是空格个数
#include <stdio.h>
#include <string.h>
#include <math.h>
int nL=0, nN=0;
int statistics(char *s)
{
_______________________
}
int main()
{
char s[81];
int nS;
gets(s);
nS = statistics(s);
printf("%d %d %d\n", nL, nN, nS);
return 0;
}
输入格式
输入一行字符,以'\n'符结束
输出格式
统计结果
输入样例
Ab 45
输出样例
2 2 1
#include<stdio.h>
#include<string.h>
#include<math.h>
int nL=0,nN=0;
int statistics(char *s)
{
int nS=0;
for(int i=0;s[i]!='\0';i++)
{
if(s[i]>='0'&&s[i]<='9') nN++;
if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z') nL++;
if(s[i]==' ') nS++;
}
return nS;
}
int main()
{
char s[81];
int nS;
gets(s);
nS=statistics(s);
printf("%d %d %d\n",nL,nN,nS);
return 0;
}