CHEFLR and Enormous Input

After Solving Enormous input question i tried to implement that method on another problems, but in CHEF LEFT-RIGHT [CHEFLR] problem from September challenge when i tried to implement Enormous input method to fetch the string at once and then manipulate the string accordingly, i found that the method failed to read the buffer.
Can anyone please help me to figure it out why that happened, Please…

//Chef Left-Right

#include<stdio.h>
#include<string.h>

#define BUFFER 1000000

int main()
{
int test, i ,value=1, length,n,j=0;
int limit=1000000007;

char array[BUFFER+1];

scanf("%d",&test);

while((n = fread(array, 1, BUFFER, stdin)))
    {
    if(test == 0)
        break;

  for(i=0; i<n; i++)
        {
    if(array[i] != '\n')
    {
        value=value%limit;

         if(j%2==0)
         {
            if (array[i]=='l')
            {
                value=((value%limit)*2)%limit;
            }
            else
            {
                value=(((value%limit)*2)%limit)+2;
            }
         }

         else
         {
             if(array[i]=='l')
             {
                 value=(((value%limit)*2)%limit)-1;
             }
             else
             {
                 value=(((value%limit)*2)%limit)+1;
             }
         }

        j++;
    }

    else
    {
        printf("%d\n",value%limit);
        j=0;
        value=1;
    }
        }
    }

return 0;
}