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

Question 4 (35 Marks) The following is a code fragment from a program that reads

ID: 3906535 • Letter: Q

Question

Question 4 (35 Marks) The following is a code fragment from a program that reads input from the console and runs the corresponding command: Structure to hold the command string and // pointer to command function typedef struct uint8t NameString uint8t Function p)(uint8t ArgNum, uinttArgStrings uint8t HelpString Array of commands const command-s commandList[] { "filtcooff", SFiltercoefffunction,"iltcooff), "help. &HelpFunction;, "helpl) NULLNULL NULL l 2 Command functions // Function to call the corresponding command uint8_t CallFunction(uinttArgNum, uint8_t ArgStrings[) main () uint8t ArgNun uint8t ArgStrings uint8t Status Status-CallFunction(ArgNum, Argstrings) A command line parser has already been written (not shown in the code fragment) which reads console input and ex tracts words from the command line, returning the number of words ArgNun and an array of strings Argstrings[ containing the words. The function CallFunction takes the returned values from the command line parser and alls the corresponding function from the command list based on the first argument from the command line. The following questions relate to the information provided above Page 10 of 12 ELEC3730 Digital and Computer Electronics 2 Practice Esamination a) The command filtcoeff reads the binary file which contains filter coefficients and prints the details to the console. The details of the file contents are The first four bytes contain an integer n which is in stored in little endian format. The next 8n bytes contain an array of n floating point numbers stored as 8 byte double precision Write the function FilterCoeffFunction) to implement the command. The function should display to the console the value of the integer n and the n floating point numbers. Ensure that the code is robust and will not cause the system to crash even with inconsistent user input.

Explanation / Answer

void FilterCoeffFunction(char *filename){

   char a[4];
   char b[4];
   int *p;
   double d;
   fp = fopen("filename","rb");
   for (i = 0; i<50; i++){
       fread(&a[0], sizeof(char),4,fp);
       printf("%d",a);
   }
   for (int i = 3; i>=0; i--){
     b[i-3] = a[i];
   }
   p = (int *)&b[0];
   printf("%d ",*p);
   for (int i = 0; i<*p; i++){
       fread(&d, sizeof(double),1,fp);
       printf("%lf ",d);
   }
}

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