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

This is an exercise for C programming?it is Better to answer it with some explan

ID: 3902973 • Letter: T

Question

This is an exercise for C programming?it is Better to answer it with some explanations?Thanks!

Codes are as follow:

1.

// lab3exe_E.c

#include "lab3exe_E.h"

#include <stdlib.h>

#include <stdio.h>

#include <math.h>

#include <string.h>

int main(void) {

    Bits_Pattern bits_array[MAX_ARRAY_SIZE];

    int size = read_bit_patterns(bits_array,"lab3exe_E.txt");

    display_bit_patterns(bits_array, size);

    fprintf (stdout, " Program terminated. ");

    return 0;

}

int read_bit_patterns(Bits_Pattern * arr, const char* filename){

    

    // in you AR diagram you don't need to show where FILE pointer, fp, points to.

    // just show the arrow points to a box with a couple of question marks,

    // anywhere besid your diagram.

    

    FILE *fp;

    int row = 0, col;

    

    fp = fopen(filename, "r");

    

    if(fp == NULL){

        fprintf( stderr, "Error: cannot open file: %s", filename);

        exit(1);

    }

    

    char c = fgetc(fp);

    

    while (c != EOF && row < MAX_ARRAY_SIZE){

        col = 0;

        while(c != ' ' && c != EOF){

            if(c != '0' && c != '1')

            {

                fprintf(stderr, "Error: Invlide character in: %s", filename);

                exit(1);

            }

            arr[row].bits[col] = c;

            col++;

            c = fgetc(fp);

        }

    

        arr[row].bits[col] ='';

        calculate_value(&arr[row]);

        row++;

        if(c != EOF)

            c = fgetc(fp);

    }

    fclose (fp);

    return row;

}

void calculate_value(Bits_Pattern * bits){

    

    int position = 0;

    bits->value =0;

    

    for ( int i = (int) strlen(bits->bits)-1; i >= 0; i-- ) {

        bits ->value = bits->value + (bits->bits[i]-48) * pow(2.00, position);

        position++;

    }

    // POINT ONE - DRAW AR DIAGRAM AT THIS POINT WHEN REACHES FOR THE SECOND TIME

    

}

void display_bit_patterns(Bits_Pattern arr[], int size){

    for(int i = 0; i < size; i++) {

        for( int j = 0; arr[i].bits[j] != ''; j++)

            fprintf(stdout, "%c", arr[i].bits[j]);

        fprintf(stdout, "       %12d ", arr[i].value);

    }

}

2.

// lab3exe_E.h

#ifndef lab3ExE_h

#define lab3ExE_h

#define MAX_BITS 5

#define MAX_ARRAY_SIZE 4

typedef struct Bits_Pattern

{

    char bits[MAX_BITS];

    int value;

    

} Bits_Pattern;

int read_bit_patterns(Bits_Pattern * arr, const char* filename);

void display_bit_patterns(Bits_Pattern arr[], int size);

void calculate_value(Bits_Pattern * byte);

#endif /* lab3ExE_h */

3.

Lab3exe_E.txt

0011

0101

1111

1001

Codes are as above, there are three files.


Exercise E: Draw AR Diagrams This is a post-lab exercise. What to Do: Download file lab3exe_E.c, lab3exe_E.h, and Iab3exe_E.txt, from D2L. This exercise receives its input from text file, lab3exe B.txt, and populates an array of structure called Bits Pattern with the available data in this file. Study the content of these files carefuily to understand what the program does. Then draw a memory when the program reaches point one for the second time. Note: in your AR diagram you don't need to show where exactly a FILE pointer points. Just mention it points to "somewhere on the memory" as following figure shows: FILE fp = fopen ("a-file name", "r"); * stack Somewhere on the fp No What to Submit: Submit your AR diagram.

Explanation / Answer

Your code looks fine and it is good explained please run if there is a logical error then ask otherwise all thing is fine.

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