My code crash coz free() doesn't want to clear array. First of all i create array and add to there a numbers. After that i enter K (k < m) and creates new matrix MxK. k - amount of number of first array in line. And if the number are over , should fill in the rest matrix with zeros. I use while for reuse, but my code crash when i use big array and big matrix. With what it can be connected?
`int main() {
    while(1){
    int m,k;
    printf("Enter size of array: ");
    int res;
    do
    {
        res=scanf("%d",&m);
        if(res!=1)printf("it should be a number!");
    }
    while(res!=1);
    int * a = (int*) malloc(m*sizeof(int)); 
    int i;
    for (i = 0; i < m; i++)
    {
        printf("a[%d] = ", i);
            do
            {
            res=scanf("%d", &a[i]);
            flush();
            if(res!=1) printf("it should be a number!\n");
            }
            while(res!=1);
    }
    for (i = 0; i < m; i++)
        printf("%d ", a[i]);
    printf("\nEnter K: ");
    do
    {
    res=scanf("%d",&k);
    flush();
    if(res!=1 || k>m) printf("k<m must be or enter number\n");
    }
    while(res!=1 || k>m);
    int all=k*m;
    for(i=m;i<all;i++)
    {
        a[i] = 0;
    }
    int j;
    int n=0;
    int s[i][j];
    for(i=0;i<m;i++)
    {
    for(j=0;j<k;j++)
    {
    s[i][j] = a[n];
    printf("%d ",s[i][j]);
    n++;
    }
    printf( "\n" );
    }
    for(i=0;i<m;i++)
    {
    for(j=0;j<k;j++)
    {
        free(s[i][j]);
    }
    }   
int povtor;   ----- exit using break
char temp[10];
printf("Continue?(1 - No, everything - Yes): ");
gets(temp);
povtor = atoi(temp);
if (povtor == 1 ) break; 
}
return 0;
}`
 
     
    