第二个我写过 ,只是不是子函数的,给你你修改一下
你可以去我Blog看看有没有你需要的程序:
http://hust-yangxiaolu.blog.163.com/
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 1024
void main()
{
char str[MAX_LENGTH];
int abCnt, spaceCnt, digitCnt, elseCnt;
int i;
char c;
abCnt = spaceCnt = digitCnt = elseCnt = 0;
printf("Input a string:");
gets(str);
for(i = 0; i < strlen(str); i++)
{
c = str[i];
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
abCnt++;
else if(c >= '0' && c <= '9')
digitCnt++;
else if(c == ' ')
spaceCnt++;
else
elseCnt++;
}
printf("abCnt = %d, spaceCnt = %d, digitCnt = %d, elseCnt = %d\n", abCnt, spaceCnt, digitCnt, elseCnt);
}
你可以去我Blog看看有没有你需要的程序:
http://hust-yangxiaolu.blog.163.com/
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 1024
void main()
{
char str[MAX_LENGTH];
int abCnt, spaceCnt, digitCnt, elseCnt;
int i;
char c;
abCnt = spaceCnt = digitCnt = elseCnt = 0;
printf("Input a string:");
gets(str);
for(i = 0; i < strlen(str); i++)
{
c = str[i];
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
abCnt++;
else if(c >= '0' && c <= '9')
digitCnt++;
else if(c == ' ')
spaceCnt++;
else
elseCnt++;
}
printf("abCnt = %d, spaceCnt = %d, digitCnt = %d, elseCnt = %d\n", abCnt, spaceCnt, digitCnt, elseCnt);
}