You're filling your array with the low-order byte of the function pointer to rand
, not with a random number. You need to call the function:
*startingPtr = (unsigned char)rand();
You also aren't incrementing startPtr
while printing out the character data. You need a startPtr++
in there:
if (asciiBytes > 0)
{
printf("%c", isgraph(*startPtr)? *startPtr:'.');
startPtr++;
asciiBytes--;
}
As it stands, your program just prints the first byte over and over again, and then goes on to the next line and prints an identical one to the previous line.