#include <stdio.h>
#include <stdlib.h>
#define size 4
int main(void)
{
char a[size] [size];
int i, j,u=0,n=0;
for(i=0;i<=size-1; i++)
{
for(j=0;j<=size-1;j++)
{
a[i] [j]= '*';
printf(" %c",a[i] [j]);
}
printf("\n");
}
printf("\n\n");
srand(time(NULL)) ;
for(;;)
{
printf("enter some thing\n");
a[rand()%size][rand()%size]=getchar();
for(i=0;i<=size-1; i++)
{
if (u==size)
break;
for(j=0;j<=size-1;j++)
{
if (a[i] [j] =='\0')
a[i] [j] ='*';
printf(" %c",a[i] [j]);
}
printf("\n");
u++;
}
n++;
if (n==2)
{
u=0;
n=0;
}
printf("\n\n");
}
return 0;
}
The problem that I'm having with this code is that; the array loses it content as it's being filled leaving out blank spaces.and further more it arrangement changes.. I don't know why my program or compiler behave like this I don't even know where is the problem from. Worse is that this behavior is unpredictable. Below is a screen shoot of what I'm trying to say
I will like that some one tells me why it is behaving like that and also to get some solutions to over come this problem.
Thanks for answering.