I’m having trouble changing the line fwrite(tmp_array, sizeof(int), num, f); to fprintf.
Can someone please take a look for me?
void generate_random_sorted_file(const char *file_name, int num)
{
FILE *f = fopen(file_name, "wb");
if (f==NULL)
{
printf("could not open %s\n", file_name);
return;
}
int *tmp_array = calloc(num, sizeof(int));
int i;
for (i=0; i<num; i++)
tmp_array[i]=rand();
qsort (tmp_array, num, sizeof(int), compare); /* sorts the array */
fwrite(tmp_array, sizeof(int), num, f);
fclose(f);
}
fprintf will write the your integer array as text, if that’s what you want, do something like