The problem deals with writing a program to geta series of integers from a user and storing those values into an array. Then use a function called selection_sort, when given an array with n elements, the function must sort the array from smallet to largest values.
I have code, and im trying to get it to compile but im getting these implicit declaration errors and conflicting types, I have no idea why im getting them. Any help is appreciated, Here is my code and the compiler errors.
Code:
Compilation started at Sun Feb 10 20:14:48
gcc -Wall -o ex9-1 ex9-1.c
ex9-1.c: In function ‘main’:
ex9-1.c:16:5: warning: implicit declaration of function ‘selection_sort’ [-Wimplicit-function-declaration]
ex9-1.c:20:2: warning: implicit declaration of function ‘prinf’ [-Wimplicit-function-declaration]
ex9-1.c: At top level:
ex9-1.c:31:6: warning: conflicting types for ‘selection_sort’ [enabled by default]
ex9-1.c:16:5: note: previous implicit declaration of ‘selection_sort’ was here
/tmp/ccKgLSrk.o: In function `main':
ex9-1.c:(.text+0xe2): undefined reference to `prinf'
collect2: ld returned 1 exit status
Compilation exited abnormally with code 1 at Sun Feb 10 20:14:49
Code:
#include <stdio.h>
int main(void) {
int a[100], i, j, N;
printf("How many numbers will you be entering: ");
scanf("%d", &N);
printf("Enter numbers to be sorted: ");
for(i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
selection_sort(a[i], N);
printf("Your sorted list of integers is : ");
for(j = 0; j < N; j++) {
prinf("%4d\n", &a[i]);
}
return 0;
}
void selection_sort(int a[], int size) {
int i, j, x;
for(i = 1; i <= size - 1; i++) {
j = i;
x = a[i];
while(a[j - 1] > x && j > 0) {
a[j] = a[j-1];
j = j - 1;
}
a[j] = x;
}
}