Holes in the text problem(Please tell me why this code is not working)

#include
#include
#include<string.h>

int main()
{  
int i,len=0,count,test,j;
char a[101];
cin>>test;
for(j=1;j<=test;j++)
{

cin>>a;

while(a[len]!='\0')
    {

        len++;
    }
   count=0;
   
   
    for(i=0;i<len;i++)
    {
    	if(a[i]=='A' || a[i]=='D' || a[i]=='P' || a[i]=='Q' || a[i]=='R' || a[i]=='O')
    	count++;
    	else 
    	if(a[i]=='B')
    	count=count+2;
    }
    cout<<count<<endl;
}
    return 0;

}

@codecrawler : Why are you checking for ‘\0’ . The new line character is ‘\n’ .

Set len = 0 “inside” the first for-loop.

1 Like

just find the length of your string using strlen() function

thnx…i will try…let me know…i should use this code

while(a[len]!=’\0’)
{
len++
}

for calculating string length or strlen fn. and why?

@codecrawler…use of above method is good…use it…strlen does the same thing(SO)…u save time of calling a fxn…though it is not a lot…but an optimization is an optimization…:stuck_out_tongue:

1 Like

i think he is finding length of string in this case(so increasing value till a null character is met)
also using namespace std is missing

you can reduce your code and stress…
For strlen hope yo know the syntax…:slight_smile:
Happy coding…:slight_smile: