Next Palindrom Code in C not working??

I tried running this code on ideonne & i got runtime error.
I also submitted it to codechef server & i got wrong answers.I ran this code on my machine & i got no problem.
Anyone help me with code

   #include<stdio.h>
#include<ctype.h>

char num[1000001] = {0};
void carry(char [], int);
int main()
{
    int test, counter, start, i, flag = 0, end;
    char bit;
    scanf("%d",&test);
    for(counter = 0; counter <= test; counter++)
    {
	flag = 0, num[0] = '0';
	while((bit = getchar()) != '\n') //storing no. in array
	    num[++flag] = bit;
	if(counter != 0) //getchar takes the input of enter key hit after writing no. of test cases so t+1 loop & removing counter = 0 case
	{
	    if(flag == 1)
		printf("%d\n",11); //if no. < 11 print 11
	    else
	    {
		end = flag;
		carry(num , end); //adding one to the number using function carry
		start = (num[0] == '0')?1:0; //if 999 no. becomes 1000 so finalizing starting position
		while(start <= end)
		{
		    if(num[start] < num[end]) 
			carry(num,(end-1));
		    if(num[start] == num[end])
			;
		    else
		    {
			num[end] = num[start];
		    }
		    start++;
		    end--;
		}
		for(i = 0; i <= flag; i++)
		{
		    if(i == 0 && num[0] == '0')
			;
		    else
		    {
			printf("%d",(num[i] - '0'));
			num[i] = '0';
		    }
		}
		printf("\n");
	    }
	}
    }
    return 0;
}

void carry(char num[], int end) //add to number
{
    int cary = 1;
    while(cary != 0)
    {
	if(num[end] == '9')
	{
	    num[end] = '0';
	    end--;
	    cary= 1;
	}
	else
	{
	num[end] = num[end] + 1;
	cary = 0;
	}
    }
}

You are taking t+1 test cases.
Change the code to for(counter = 0; counter < test; ++counter) or for(counter = 1; counter<= test; ++coounter)

i am taking t+1 cases becz getchar takes the input of enter key after i input no. of test cases.

oh sorry i didnt see that

anyone help …