#include<stdio.h>
int main()
{
int t,count,i;
char str[100];
scanf("%d",&t);
while(t>0)
{
i=0;count=0;
scanf("%s",str);
while(str[i]!='\0')
{
switch (str[i])
{
case 'A':
case 'D':
case 'O':
case 'P':
case 'Q':
case 'R':
count++;
break;
case 'B':
count+=2;
break;
}
i++;
}
printf("%d\n",count);
t--;
}
return 0;
}
This works fine but if I put gets(str) instead of scanf("%s",str) then it gives me a wrong ans. Can someone explain why?
but you don’t know how many blank lines user will input, and therefore how many newline characters are…scanf() will take care even if there are 2 or more blank lines