/*参考答案*/
#include
#include
#include
#include
char xx[50][80] ;
int yy[5] ;
int maxline = 0 ; /* 文章的总行数 */
int ReadDat(void) ;
void WriteDat(void) ;
void ComWord(void)
{
int i,j,k,n,len,s[4] = {2,4,6,8};
memset(yy,0,5*sizeof(int));
for(i = 0; i < maxline; i++)
{
len = strlen(xx);
n = 0;
for(j = 0; j < len+1; j++)
{
c = xx[j];
if((c>='a' && c<='z') || (c>='A' && c<='Z'))
{
word[n] = c;
n++;
}
else
{
word[n] = '\0';
if(word[0] != '\0')
{
for(k = 0; k < 4; k++)
if(n == s[k])
yy[k]++;
yy[4]++;
}
n = 0;
}
}
}
}
void main()
{
int i ;
clrscr() ;
for(i = 0 ; i < 5 ; i++) yy = 0 ;
if(ReadDat()) {
printf("数据文件ENG.IN不能打开!\n\007") ;
return ;
}
ComWord() ;
WriteDat() ;
}
希望与更多计算机等级考试的网友交流,
.
www.59wj.comint ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;
if((fp = fopen("eng.in", "r")) == NULL) return 1 ;
while(fgets(xx, 80, fp) != NULL) {
p = strchr(xx, '\n') ;
if(p) xx[p - xx] = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
int i ;
for(i = 0 ; i < 5 ; i++) fprintf(fp, "%d\n", yy) ;
printf("单词长度为3的单词数=%d\n", yy[0]) ;
printf("单词长度为5的单词数=%d\n", yy[1]) ;
printf("单词长度为7的单词数=%d\n", yy[2]) ;
printf("单词长度为9的单词数=%d\n", yy[3]) ;
printf("单词的总数=%d\n", yy[4]) ;
fclose(fp) ;
}
希望与更多计算机等级考试的网友交流,
.
www.59wj.com 如果觉得《计算机等级考试二级C上机模拟试题及答案》二级C上机题库,jsj不错,可以推荐给好友哦。