Why the FOR LOOP is not working properly?(NEW BUG)

int t;
scanf("%d",&t);
int i;
for(i=0;i<t;i++)
{ int n;
    scanf("%d",&n);
    char str[n+1];
    char str1[n+1];
    scanf("%s",str);
    int l=0,j=0;
    while(l<n)
    {
        if(str[l]=='H')
        {
            str1[j]='H';
            j++;
            
            }
        else if(str[l]=='T')
        {
            str1[j]='T';
        
            j++;
        }
        l++;
    }
    int ll,jj;
    ll=strlen(str1);

      printf("%d\n",ll);
          printf("%s\t",str1);
      printf("\n");
      int counter=0;
      if(str1[0]=='T')
      {
          printf("INVALID\n");
          
      }
      
      else if(str[0]!='T')
    {
        for(jj=0;jj<ll-1;jj++)
    {
        
        if(str1[jj]=='H'&&str1[jj+1]=='H')
        {
            counter++;
        }
        else if(str1[jj]=='T'&&str1[jj+1]=='T')
        {
            counter++;
        }
        
    }
    if(counter>0)
    printf("INVALID\n");
    else
    printf("VALID\n");
    }
    
    }

}

What is the issue exactly and it would be better if you provided the link of the solution / code.
Copy pasting makes it messy, always try to provide a link to the solution :slightly_smiling_face:.

2 Likes

OK, from the next time i will do like that :grinning:

1 Like

I solved this problem , thanks for helping ! :v:
Actually, I forgot to end the str1 by ‘\0’.
So, I was getting the error.

1 Like