Need help debugging code - Program uses function to sort array
I have been working on this all day and cant seem to work anything out.The program accepts the array values and stops. No compiler errors.
:confused:
Any help whatsoever is greatly appreciated!
Code:
#include <stdio.h>
#include <stdlib.h>
int *ptr;
int* sort(int numbers[], int size);
int main(int argc, char *argv[])
{
//declaring variables//
int x;
int i;
int counter;
int place1;
int place2;
int place3;
int place4;
int p;
int size;
//Prompts for and accepts integers//
printf("How many integers in array?\n");
scanf(" %d", &size);
int numbers[size];
for(i=0;i<(size);i++)
{
printf("Enter Number #%d ", i+1);
scanf(" %d", &numbers[i]);
}
//sorts array//
ptr = sort(numbers,size);
//prints sorted array//
for(p=0;p<size;p++)
{
printf(" %d", *(ptr+p));
}
system("PAUSE");
return 0;
}
int* sort(int numbers[], int size)
{
//declaring variables//
int x;
int smallest;
int holdsvar;
int y;
//sorts array by finding min value//
for(x=0; x=(size-1) ; x++)
{
smallest=x;
for(y=x; y=(size-1); y++)
{
if (numbers[y] < numbers[smallest])
{
smallest=y;
}
}
//switches analysed spot(0->array size) with smallest value//
holdsvar=numbers[x];
numbers[x]=numbers[smallest];
numbers[smallest]=holdsvar;
}
return &numbers[0];
}