This program has runtime error. I can't find it.

,

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

int main()
{
    char ch[101];
    int len,i,j,start,en,a,group;
    while(scanf("%d",&group)!=0)
    {
        if(group==0)
            break;
        else
        {
            gets(ch);
            len=strlen(ch);
            a=len/group;
            start=0;
            en=0;
            for(i=0;i<len;i++)
            {
                if( (i+1)%a==0)
                {
                    en=i;
                    for(j=en;j>=start;j--)
                    {
                        printf("%c",ch[j]);
                    }
                    start=en+1;
                }
            }
        }
    }
    printf("\n");
}

It fails for example for input

4 ab

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

int main()
{
    char ch[1000];
    int len,i,j,start,a,group;
    while(scanf("%d\n",&group)!=0)
    {
        if(group==0)
            break;
        scanf(" ");
        gets(ch);
        len=strlen(ch);
        a=len/group;
        if(len<group*2)
            puts(ch);
        else
        {
            for(i=1;i<=len;i++)
            {
                start=a*i;
                for(j=start-1;j>=start-a;j--)
                {
                    printf("%c",ch[j]);
                }
            }
        }
    }
    printf("\n");
}

again i find runtime error

i solved the problem. but again i find runtime error

What about

4 abc

?