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

/***************************************************************** * This progra

ID: 3670338 • Letter: #

Question

/*****************************************************************

* This program finds the edges of light and dark regions of the

* input binary bit pattern.

* ***************************************************************/

#include <stdio.h>

void edge(int n, int a[], int b[]);

int main(void)

{

   int input[8]={0};

   int output[8];

   int i;

   printf("please enter the 8 bit bar code");

   for(i=0;i<8;i++)

       scanf("%1d", &input[i]);

   edge(8, input, output);

   for(i=0;i<8;i++)

       printf("%d", output[i]);

   return 0;

}

void edge(int n, int a[], int b[])

{

   int i;

   b[0]=0;

   for (i = 1;i<n; i++)

       if(a[i]==a[i-1])

           b[i]=0;

       else

           b[i]=1;

}

1. Note: This program will be graded based on whether the required functionality were implemented correctly instead of whether it produces the correct output, for the functionality part (80% of the grade).

Modify barcode.c, the edge detection function using pointer arithmetic. The function prototype should be the following. Name your program barcode2.c.

The function should use pointer arithmetic – not subscripting – to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.

barcode.c

Explanation / Answer

#include <stdio.h>
void edge(int n, int *a, int *b);
int main(void)
{
    int *input={0,0,0,0,0,0,0,0};
    int *output;
    int i;
    printf("please enter the 8 bit bar code");
    for(i=0;i<8;i++)
        scanf("%1d", (input+i));
    edge(8, input, output);
    for(i=0;i<8;i++)
        printf("%d", *(output+i));

    return 0;
}
void edge(int n, int *a, int *b)
{
    int i;
    *(b+0)=0;
    for (i = 1;i<n; i++)
        if(*(a+i)==*(a+i-1))
            *(b+i)=0;
        else
            *(b+i)=1;
}