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

1. (30 points) Note: This program will be graded based on whether the required f

ID: 3669765 • Letter: 1

Question

1. (30 points) 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 (attached, Project 4, #2), the edge detection function using pointer arithmetic. The function prototype should be the following. Name your program barcode2.c.

void edge(int n, int *a1, int *a2);

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

//Name: Linqi Wang      U#: U03948584
//Find the edges of light and dark regions

#include <stdio.h>

//function
void edge(int n, int a1[], int a2[]);

int main()
{
      int array1[8], array2[8];
      int i;
      char ch;

      //for loop to get input
      printf("Input: ");
      for(i = 0; i < 8; i++)
      {
         scanf("%c", &ch);
         if(ch == '1'){
         array1[i] = 1;}
         else{
         array1[i] = 0;}
      }

      edge(8, array1, array2);
      printf("Output: ");
      for(i=0; i < 8; i++)
      {
         printf("%d", array2[i]);
      }
      printf(" ");

      return 0;
}

void edge(int n, int a1[], int a2[])
{
      int previous_bit = a1[0];
      a2[0] = 0;
      int i;
      for(i = 1; i < n; i++)
      {
         if(previous_bit == a1[i]){
            a2[i] = 0;}
         else{
            a2[i] = 1;}
         previous_bit = a1[i];

      }

}

Explanation / Answer

Program:

#include <stdio.h>

void edge(int n, int *a1, int *a2);

int main()
{
int array1[8], array2[8];
int i;
char ch;

//for loop to get input
printf("Input: ");
for(i = 0; i < 8; i++)
{
scanf("%c", &ch);
if(ch == '1'){
array1[i] = 1;}
else{
array1[i] = 0;}
}

edge(8, array1, array2);
printf("Output: ");
for(i=0; i < 8; i++)
{
printf("%d", array2[i]);
}
printf(" ");

return 0;
}

void edge(int n, int *a1, int *a2)
{
int previous_bit = *a1;
*a2 = 0;
int i;
for(i = 1; i < n; i++)
{
if(previous_bit == *(a1+i)){
*(a2+i) = 0;}
else{
*(a2+i) = 1;
       }
previous_bit = *(a1+i);

}

}