How to print empty array elements / skip array elements in C?

advertisements

So I have 3 int type arrays, A, B and C. The program checks array A elements for prime numbers, if the number is prime in array it gets copied to array B, if not array C. Later it prints all three arrays.

This is the code piece a have problems with:

    if(onalg)
    {
    B[i]=A[i];
    }
    else
    {
    C[i]=A[i];
    }

Then sort the array B and C using qsort ( done this, works ). After all that it has to print all arrays like this:

for(i=0;i<n;i++)
{
    printf("%d        %d        %d\n", A[i],B[i], C[i]);
}

How can I make it print empty spots in array? Currently it prints some random numbers in array C[i] spot when B[i]=A[i] and in array B[i] when C[i]=A[i].


You cannot.
You will need to assign some value to your array member which will indicate it is not initialized and then check for that value and treat it as blank while printing it out.

if(onalg)
{
    B[i]=A[i];
    C[i]= //Some place holder value indicating unfilled;
}
else
{
    C[i]=A[i];
    B[i]= //Some place holder value indicating unfilled;
}