I had a particular problem with a simple function that I created. This function generates a random number between 0-14, then creates an array using this randomly generated number as a size and fills it with char 'x'.
The problem I am facing is that when I call the function, it will randomly display characters or numbers after x.
I initially declared an array of size 15, but thought these were the remaining slots causing this display problem. However, it still persists after changing the function.
Here's the current function I'm using:
void application()
{
int randSize, i;
srand((unsigned)time(NULL));
randSize = (rand() % 15);
char array[randSize];
char *bar = array;
for(i=0; i< randSize; i++)
array[i] = 'x';
printf("%s | ", bar);
}
source
share