GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Find a bug in code and correct it(Online test question)

Below is almost correct program, there is only one line code is wrong, you have to fix it.

input String str contains only a and b characters, below code checks whether str contains qual number of a and b characters

void checkBalance(string str)
{
  char temp[MAXLEN];
  int i,j;
  for( i=j=0; temp[i] = str[j]; j++)
   if(strpj[ == temp[i])
	i++;
   else
        i--;
   if(i ==0)
      printf("Balanced\n");
   else
      printf("Not Balanced\n");
}

 

asked Nov 19, 2015 by sivarank

2 Answers

If(str[j] ==temp[i] )
answered Dec 16, 2016 by anonymous
For (i=j=0; temp[i]==str[j]; j++) And str[j]==temp[i]
answered Dec 17, 2016 by Vidya G
...