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

CODE IN C /** * Function: extract_window * Description: populates 2D array windo

ID: 650365 • Letter: C

Question

CODE IN C
/**
* Function: extract_window
* Description: populates 2D array window with sub-matrix
*               of landscape 2D array starting at column
*               start_col.
*               Returns 1 on success, 0 on failure.
*               Fails when start_col is not valid -- i.e.,
*               specifies a window not contained in the
*               landscape.
*
* Note: nrows applies to both the landscape and the window.
*/
extern int extract_window(char landscape[][L_WIDTH],
                                char window[][W_WIDTH],
                                int nrows, int start_column);

Explanation / Answer

#include <stdio.h>

#include "a.c"
#define L_WIDTH 80
#define W_WIDTH 20

extern int extract_window(char landscape[][L_WIDTH], char window[][W_WIDTH], int nrows, int start_column){
if(start_column + W_WIDTH > L_WIDTH) return 0;
int i, j;
for(i = 0; i < nrows; i++){
for(j = start_column; j < start_column + W_WIDTH; j++){
landscape[i][j] = window[i][j];
}
}
return 1;
}

int main(){
char l[10][L_WIDTH], w[10][W_WIDTH];
int i, j;
for(i = 0; i < 10; i++){
for(j = 0; j < W_WIDTH; j++){
w[i][j] = '*';
}
}
for(i = 0; i < 10; i++){
for(j = 0; j < L_WIDTH; j++){
l[i][j] = ' ';
}
}
int temp = extract_window(l, w, 10, 5);
if(temp == 0){
printf("Invalid values ");
return 0;
}

for(i = 0; i < 10; i++){
for(j = 0; j < L_WIDTH; j++){
printf("%c", l[i][j]);
}
printf(" ");
}
}

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