Im not sure why this bubble sort code isn't working at all, could someone give me a hint ?
Help would be much appreciated. Thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int array[2];
int temp[2][2];
int checkint(char s[]) //Checks if string is purely numerical
{
int length = strlen(s); // Define string length
for (int i = 0; i < length; i++) // For each character
{
if (isdigit(s[i])); // If numerical, then do nothing
else return 0; //If not, then return 0
}
return 1;
}
static void bubble_sort(int r[], int y)
{
int i, j, temp;
for (i = 0; i < y-1; i++);
for (j = 0; j < y-i-1; j++);
if (r[j] > r[j + 1])
{
temp = r[j];
r[j] = r[j + 1];
r[j + 1] = temp;
}
}
int main(int argc, char *argv[])
{
int temp = (argc - 2);
array[temp];
if(argc < 2) //Check if enough arguments have been supplied
{
printf("Too few arguments for this program.\n");
exit(EXIT_FAILURE); //If not then exit
}
else
{
for (int i = 1; i < argc; i++) //For every argument provided (excluding 0)
{
int ans = atoi(argv[i]); //Find the int equivalent
int var = (i-1);
array[var] = ans; //Store it in the array
}
bubble_sort(array, argc);
for (int a = 0; a < argc-1; a++)
printf("%d ", array[a]);
printf("\n");
}
// Exit indicating success
exit(EXIT_SUCCESS);
return 0;
}