检查以下字符串指针数组中的元音?
Checking for vowels in the following array of pointers to strings?
#include <stdio.h>
#include <string.h>
main()
{
char *a[]={"FrIiends is an american television sitcom", //*line to be checked*
"created by David crane and marta kauffman",
"which originally aired on NBC"};
int i=0,len=0,j=0,count=0; //Initialization of certain variables
for(i=0;i<3;i++){
count=0; //Count always made 0 for new line
len=strlen(*(a+i)); //Lenght for new line is stored here every time
for(j=0;j<len;j++){
if((int)*(*(a+i)+j)==97 || (int)*(*(a+i)+j)==101 || (int)*(*(a+i)+j)==105 || (int)*(*(a+i)+j)==111 || (int)*(*(a+i)+j)==117) //checking for vowels in lowercase
count=count +1;
if ((int)*(*(a+i)+j)==65 || (int)*(*(a+i)+j)==69 || (int)*(*(a+i)+j)==73 || (int)*(*(a+i)+j)==79 || (int)*(*(a+i)+j)==85) //checking for vowels in Uppercase
count=count+1;
}
printf("Vowels in line %d are:%d\n",i+1,count); //Final print statement
}
}
以下代码可以正常工作,但是是否有其他方法可以计算以下指向数组的指针中的元音?
使用起来似乎也相当低效。
在我上面的例子中,我为上部和下部做了巨大的测试用例 case.Is 有一种方法可以忽略大小写或类似的东西。
#include <stdio.h>
#include <ctype.h>
int main(void){
char *a[]={"FrIiends is an american television sitcom",
"created by David crane and marta kauffman",
"which originally aired on NBC"};
char *p, ch;
int i, count;
for(i=0; i<3; ++i){
count=0;
p = *(a + i);//a[i];
while(ch=tolower(*p++)){
if(ch=='e' || ch=='a' || ch=='i' || ch=='o' || ch=='u')
++count;
}
printf("Vowels in line %d are:%d\n", i+1, count);
}
return 0;
}
#include <stdio.h>
#include <string.h>
main()
{
char *a[]={"FrIiends is an american television sitcom", //*line to be checked*
"created by David crane and marta kauffman",
"which originally aired on NBC"};
int i=0,len=0,j=0,count=0; //Initialization of certain variables
for(i=0;i<3;i++){
count=0; //Count always made 0 for new line
len=strlen(*(a+i)); //Lenght for new line is stored here every time
for(j=0;j<len;j++){
if((int)*(*(a+i)+j)==97 || (int)*(*(a+i)+j)==101 || (int)*(*(a+i)+j)==105 || (int)*(*(a+i)+j)==111 || (int)*(*(a+i)+j)==117) //checking for vowels in lowercase
count=count +1;
if ((int)*(*(a+i)+j)==65 || (int)*(*(a+i)+j)==69 || (int)*(*(a+i)+j)==73 || (int)*(*(a+i)+j)==79 || (int)*(*(a+i)+j)==85) //checking for vowels in Uppercase
count=count+1;
}
printf("Vowels in line %d are:%d\n",i+1,count); //Final print statement
}
}
以下代码可以正常工作,但是是否有其他方法可以计算以下指向数组的指针中的元音? 使用起来似乎也相当低效。 在我上面的例子中,我为上部和下部做了巨大的测试用例 case.Is 有一种方法可以忽略大小写或类似的东西。
#include <stdio.h>
#include <ctype.h>
int main(void){
char *a[]={"FrIiends is an american television sitcom",
"created by David crane and marta kauffman",
"which originally aired on NBC"};
char *p, ch;
int i, count;
for(i=0; i<3; ++i){
count=0;
p = *(a + i);//a[i];
while(ch=tolower(*p++)){
if(ch=='e' || ch=='a' || ch=='i' || ch=='o' || ch=='u')
++count;
}
printf("Vowels in line %d are:%d\n", i+1, count);
}
return 0;
}