程序3 有一篇短文不超过500个字符,求其首字母为a的单词的个数。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//函数名 fun
//函数功能 计算字符串中首字母为a的单词个数
//输入参数 char text[] 字符串数组 int n数组长度
//返回值 int 首字母为a的单词个数
int fun(char text[],int n)
{
int i;
int getwordhead=1;
int result=0;
for(i=0;i<n;i++)
{
if(getwordhead)
{
getwordhead=0;
if(text[i]=='a')
{
result++;
continue;
}
}
if(text[i]==' '||text[i]==','||text[i]=='.'||text[i]=='"'||text[i]=='\n')
getwordhead=1;
}
return result;
}