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: 3794841 • 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.

#include <stdio.h>
#define N 8
void edge(int n, int *a, int *b);
int main(void)
{
   int input[N]={0};
   int output[N];
   int *p;
   printf("please enter the %d bit bar code: ", N);
   for(p=input; p< input + N;p++)
{
       scanf("%1d", p);
}
   edge(N, input, output);
   for(p= output;p<output + N;p++)
{
       printf("%d", *p);
}
   return 0;
}
void edge(int n, int *a, int *b)
{
   int *p;
   *b =0;
   for (p = b+n;p< b+n; p++)
{
       if(*a == *(a-1))
{
           *(b+ n)=0;
}
       else
{
           *(b+n) =1;
}
}
}

getting really weird numbers as my answer can anybody please help me?

Explanation / Answer

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

edge(N, input, output);
for(p= output;p<output + N;p++)
{
printf("%d", *p);
}

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

/*

I have fixed your edge function but am not able to completely verify as you have not provided on what is expected behaviour.

*/