please help me understand what I did wrong.
Code:
ssma-imac:ENG-3211 ssma$ gcc -g hw_5_2.c -o hw_5_2hw_5_2.c:61: warning: conflicting types for ‘ReadArray’
hw_5_2.c:43: warning: previous declaration of ‘ReadArray’ was here
hw_5_2.c:69: warning: conflicting types for ‘SearchArray’
hw_5_2.c:44: warning: previous declaration of ‘SearchArray’ was here
that is the error on the following code:
Code:
#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#include<math.h>
#define SIZE 10
// 1. assume that the target has not been found
// 2. start with initial array element
// 3. repeat while the target is not found and there are more array elements
// 4. if the current element matches the target
// 5. set a flag to indicate that the target has been found
// else
// 6. advance to the next array element
// 7. if the target was found
// 8. return the target index as the search result and display an appropriate message
// else
// 9. return -1 as the search result and display an appropriate message
// * this algorithm is known as the Linear Search Algorithm
void ReadArray(int A[], int size);
void SearchArray(int A[], int target, int size);
int main(void)
{
int A[SIZE], target, size;
ReadArray(A, SIZE);
printf("Please enter the value to search for: ");
scanf("%d", &target);
SearchArray(A, target, SIZE);
return(0);
}
ReadArray(int A[], int size)
{
int i;
printf("Please enter %d integer numbers separated by spaces:\n", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}
SearchArray(int A[], int target, int size)
{
int i;
for (i = 0; i < size; i++)
{
if ( target == A[i])
printf("Element %d contains the target %d", i, target);
else
printf("Target %d was not found", target);
break;
}
}
I have everything declared as int, so i dont get previous declaration, and what does conflicting type mean?
Thanks.