Hole in a letter

I have worked this logic in the Codeblocks compiler and it works near perfect.
Why does it show a segmentation fault in codechef?
#include<stdio.h>
#include<string.h>
int main()
{
char a[20];
int count,i,n;
count=0;
scanf("%d",&n);
while(n–)
{
count=0;
printf("\nEnter the String:\t");
scanf("%s",a);
for(i=0;a[i]!=’\0’;i++)
{
switch(a[i])
{
case’A’:
case’O’:
case’P’:
case ‘R’:
case ‘D’:
count++;
break;
case ‘B’:
count+=2;

        }
    }
    printf("\n%d",count);
}

return 0;

}

@agneymenon

First thing you are not required to print anything except what you are asked to, So remove print statement printf(“Enter the String”); as this is not asked to print in problem.

Second thing in problem it is mentioned this line:

The length of the text is less then 100

So if you declare size of a as 20, there will be a sure case of overflow if size of input will be >20 and thus you are getting a segmentation fault.

Thus initialize a[105] and remove print statement…

@agneymenon
You need not to write anything except what you are asked to…and one more thing that i found is that you forgot to include ‘Q’ test case…‘Q’ contains one hole in it…

happy coding

Thank U :slight_smile:
Added that

That Worked!!
Thank You :slight_smile:

most welcome… :slight_smile:

everything is suggested by comments above , i will like to add one thing , you are missing one letter :slight_smile:
go and get AC now .

you are welcome brother… :slight_smile: