I'm trying to pass values from the main() function to the selectionSort() function, but it keeps saying the following:
hw2n1.c: In function `main':
hw2n1.c:25: warning: passing arg 1 of `selectionSort' makes pointer from integer without a cast
hw2n1.c:25: error: void value not ignored as it ought to be
The following is my code:
Code:
#include <stdio.h>
#define NUM_INT 1000
void selectionSort(int a[], int size);
int main (void)
{
int input[NUM_INT] = {0};
int i;
int sorted;
printf("please input arrays of ints to be sorted ");
for (i = 0; i < NUM_INT; i++)
{
scanf("%d", &input[i]);
printf("%d ", input[i]); //TESTING
if (input[i] < -2)
{
printf("program error (one of the numbers is less than -2)\n ");
return 0;
}
if(input[i] == -1)
{
printf("restart sort and new line");
sorted = selectionSort(input[i], NUM_INT); //TROUBLE SPOT, DON'T KNOW WHAT TO DO!
}
if (input[i] == -2)
{
printf("Inputed Arrays are: %d", input[i]);
}
}
// printf("Inputed Arrays are: %d", input[i]);
printf("sorted is: %d", sorted);
return 0;
}
//SELECTION SORT ALGORITH
void selectionSort(int a[], int size)
{
int i, j, min;
for (i = 0; i < size - 1; i++)
{
min = i;
for (j = i+1; j < size; j++)
{
if (a[j] < a[min])
min = j;
}
swap(a[i], a[min]);
}
}