You are not logged in. Please login at www.codechef.com to post your questions!

×

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;
}

asked 06 Jan '14, 21:42

chrg's gravatar image

3★chrg
16113
accept rate: 0%

edited 06 Jan '14, 21:47

kunal361's gravatar image

4★kunal361
6.0k133272


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 .

link

answered 06 Jan '14, 22:22

rackstar's gravatar image

2★rackstar
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,461
×24

question asked: 06 Jan '14, 21:42

question was seen: 3,324 times

last updated: 06 Jan '14, 22:22