I'm currently working on CS50's Lab 4 - Volume. I have the following code and I'm wondering if it's okay to use the same pointer name in two separate places after calling free on it.
//Initialize tmp pointer and copy header bytes from input to output file
uint8_t *tmp = malloc(sizeof(uint8_t));
if (*tmp == NULL)
{
printf("Mem_ERR_2\n");
return 2;
}
for (int b = 0; b < 44; b++)
{
*tmp = fgetc(*input);
*output = fputc(*tmp);
printf("H_BYTE = %i\n", b++);
}
free(*tmp);
I have *tmp
initialized, dereferenced it, and now I'm calling free on it. After this I want to create a second *tmp
pointer for a different part of code. My question is, it it good practice, or even syntactically okay to initialize uint16_t *tmp
for a second pointer? Or should I change them to *tmp1
and *tmp2
?