Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone please help fix the following C code? The program has to be done u

ID: 3813942 • Letter: C

Question

Could someone please help fix the following C code? The program has to be done using two functions (main and read_funct), and the read_funct() prototype is fixed, i.e. MUST BE: read_funct(int *data_num, double **data_vals). The code is meant to draw data from a file, where the first 4 bytes are the number of data points (data_num). The next (8*data_num) bytes contain the data values (data_vals). The program calls on read_funct(), which prints the relevant data out. Then it must be printed out again in main() as a check. An appropriate .bin file to run the code can be found here: (https://www.4shared.com/file/lCZg1MMQca/filename.html).

A dynamically allocated array has to be used for data_vals (malloc() must be used, and a pointer passed back to the data values pointed to by data_vals). I'm pretty sure it's an issue with the way I'm done data_vals.

read_funct() is below:

int read_funct(int *data_num, double *data_vals[])
{
FILE * fp = fopen("filename.bin", "rb"); //Opening file

   char buffer_n[4];
   fread(buffer_n, 4, 1, fp);
   int result = buffer_n[0]|(buffer_n[1] << 8)|(buffer_n[2] << 16)|(buffer_n[3] << 24); //Convert endian

   *data_num = result;                           //Passes results back to data_num
   printf("Number of Data Values: %d ", *data_num); //Printing results

   //Proceeds with calculating data_vals
   double **buffer_v;                           //Initialise buffer to hold coeff. values
   buffer_v = malloc(8*result); //Allocating memory
   fread(buffer_v, 8, result, fp);            //Reading into buffer

//Prints data_vals
for(int i=0; i {
printf("%0.3lf ", buffer_v[i]);
}
   data_vals = buffer_v;                       //Pass to data_vals
   free(buffer_v);                               //Free() for malloc()
printf(" End of File Read. ");
fclose(fp);
return(0);
}

main() is below:

int read_funct(int *data_num, double *data_vals[]);

int main()
{
int data_num;
double **data_vals;

//Reads file using read_funct()
read_funct(&data_num, &data_vals);

//Check: print data_num
printf(" Check No. of Values: %d ", data_num);
  
//Check: print data_vals
for(int i = 0; i {
printf("%0.3lf ", data_vals[i]);
}
return(0);
}

Thank you!

Explanation / Answer

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#define MAX_VALUE 65536
using namespace std;

/* category Node */

class Node
;

/* category ThreadedBinarySearchTree */

class ThreadedBinarySearchTree
builder */
ThreadedBinarySearchTree()
  

/* perform to clear tree */
void makeEmpty()
  

/* perform to insert a key */
void insert(int key)

else if (p-&gt;key &gt; key)
  
else
  
}
Node *tmp = new Node();
tmp-&gt;key = key;
tmp-&gt;rightThread = tmp-&gt;leftThread = true;
if (p-&gt;key &lt; key)
facet */
tmp-&gt;right = p-&gt;right;
tmp-&gt;left = p;
p-&gt;right = tmp;
p-&gt;rightThread = false;
}
else
  
}

/* perform to look for a part */
bool search(int key)
come false;
tmp = tmp-&gt;right;
}
else if (tmp-&gt;key &gt; key)
come false;
tmp = tmp-&gt;left;
}
else
come true;
}
}
}

/* Fuction to delete a part */
void Delete(int key)

else if (dest-&gt;key &gt; key)
  
else
  
}
Node *target = dest;
if (!dest-&gt;rightThread &amp;&amp; !dest-&gt;leftThread)
2 children*/
p = dest;
/* realize largest node at left kid */
target = dest-&gt;left;
whereas (!target-&gt;rightThread)
  
/* exploitation replace mode*/
dest-&gt;key = target-&gt;key;
}
if (p-&gt;key &gt;= target-&gt;key)

else if (target-&gt;rightThread)
{
Node *largest = target-&gt;left;
whereas (!largest-&gt;rightThread)
  
largest-&gt;right = p;
p-&gt;left = target-&gt;left;
}
else
{
Node *smallest = target-&gt;right;
whereas (!smallest-&gt;leftThread)
  
smallest-&gt;left = target-&gt;left;
p-&gt;left = target-&gt;right;
}
}
else
  
else if (target-&gt;rightThread)
{
Node *largest = target-&gt;left;
whereas (!largest-&gt;rightThread)
  
largest-&gt;right = target-&gt;right;
p-&gt;right = target-&gt;left;
}
else
{
Node *smallest = target-&gt;right;
whereas (!smallest-&gt;leftThread)
  
smallest-&gt;left = p;
p-&gt;right = target-&gt;right;
}
}
}

/* perform to print tree */
void printTree()
{
Node *tmp = root, *p;
for (;;)
{
p = tmp;
tmp = tmp-&gt;right;
if (!p-&gt;rightThread)
{
whereas (!tmp-&gt;leftThread)
  
}
if (tmp == root)
break;
cout&lt;&lt;tmp-&gt;key&lt;&lt;" ";
}
cout&lt;&lt;endl;
}
};

/* Main Contains Menu */

int main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote