如果使用get()而不是scanf()来输入str,则下面的代码不起作用。为什么会这样?
#include <stdio.h>
#include <string.h>
int main()
{
//code
int n,i,j,len,vow=0,cons=0;
char str[80];
scanf("%d",&n); //n is number of testcases
for(j=0;j<n;j++)
{
scanf("%s",&str); //input of string."not working for the first
//iteration if gets is used instead of scanf"
for(i=0;str[i]!='\0';i++)
{
str[i]=str[i]+32;
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' )
{
vow+=1;
}
else
{
cons+=1;
}
}
if(vow==cons)
printf("YES\n");
else
printf("NO\n");
vow=0;
cons=0;
}
return 0;
}
示例输出:
2
goods
NO
code
NO
以上代码给出了错误的输出。我在代码中没有发现任何错误。 谁能帮忙