|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 256
int count_vocal(char* buf){
int i;
int vocal = 0;
for(i = 0; buf[i] != '.'; i++){
if(tolower(buf[i]) == 'a' || tolower(buf[i]) == 'i' || tolower(buf[i]) == 'u'
|| tolower(buf[i]) == 'e' || tolower(buf[i]) == 'o')
vocal++;
}
return vocal;
}
int count_word(char *buf){
int i;
int word = 0;
char seps[] = ", .";
char *token;
token = strtok(buf,seps);
while(token != NULL){
word++;
token = strtok(NULL,seps);
}
return word;
}
int main(void){
char buf[N];
char *p = buf;
int len, i;
do{
puts("英文の入力");
fgets(buf,N,stdin);
len = strlen(buf);
}while(buf[len - 2] != '.');
if(buf[len - 1] == '\n') buf[len - 1] = '\0';
for(i = 0; buf[i] != '\0' && !isalpha(buf[i]); i++){
p = &buf[i];
}
printf("母音数:%d\n",count_vocal(p));
printf("単語数:%d\n",count_word(p));
return 0;
}
|