holes in the text..getting o/p bt SEGMENTATION FAULT (CORE DUMPED)..WHY

#include
#include

int main()
{
int num,i,count,j;
std::cin>>num;
std::string *mystring=NULL;
mystring=new std::string[num];

for(i=0;i<num;i++)
{
	std::cin>>mystring[i];
}
for(i=0;i<=num;i++)
{
	count=0;
	for(j=0;j<(mystring[i].length());j++)
	{
		if(mystring[i][j]=='A'|| mystring[i][j]=='D'|| mystring[i][j]=='O'|| mystring[i][j]=='P'|| mystring[i][j]=='Q'|| mystring[i][j]=='R')		
			{
				count++;
			}
		else if(mystring[i][j]=='B')
			count+2;
	}

std::cout<<count<<std::endl;
}
delete[] mystring;
return 0;

}

It is because you are trying to access one extra string in the second for loop.
Condition for the second for loop should be same as first one i.e. i < num and not i <= num.
Also you have to store the incremented value of count in case of ‘B’, else you will get WA.

1 Like

i think its bcoz of i m not intializing the array properly…the 2nd dimension i ithink

thanks!!that did it…

welcome :slight_smile: