Runtime Error(SIGSEGV)

CODE IN C RUNNING CORRECTLY IN DEV BUT IN THIS Runtime Error(SIGSEGV)

#include<stdio.h>
int main()
{
char s[20];
int i,cnt=0,n,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",s);
for(j=0;s[j]!='\0';j++)
{
if(s[j]=='A' || s[j]=='D' || s[j]=='P' ||s[j]=='R' || s[j]=='O' ||s[j]=='Q')
cnt++;
else if(s[j]=='B')
cnt+=2;
}
printf("%d\n",cnt);
cnt=0;
}
return 0;
}
1 Like

I think this should work
remove cnt=0 below the printf statement and place this cnt=0 at the starting of the for loop before the scanf statement .
Also dont give cnt =0 during the initialization .