I'm studying for a programming class where were learning C, and I'm doing a practice problem that I can't get right. I feel like it should be easy but somethings wrong. The program is just to use a given array and find whether or not theres a repeat in it. If there is the value of the repeat should be displayed, if not -1 should be. Heres my code:
Code:
#include<stdio.h>
int firstRepeat(int* input, int size);
int main() {
int n = 5;
int myArray[5] = {1,2,3,4,4};
int fRepeat;
fRepeat = firstRepeat(myArray, n);
printf("First repeating integer: %d\n", fRepeat);
return 0;
}
int firstRepeat(int* input, int size) {
int i, test, value;
input=&i;
for(i=1; i<size; i++) {
test = *input - *(input-1);
if(test == 0) value = *input;
else value = -1;
}
return value;
}
The function needs to use int* input and int size, so the function needs to work similar to how I have it. My problem is clearly it should display the repeat to be 4, yet i get -1 each time. I'm pretty stuck so any help is appreciated. Thanks in advance