The following code is supposed to order the surnames alphabetically but for some reason it stops, the compiler does not mark any warning, nor error so if someone knows what happens explain to me what happens please
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
double performancecounter_diff(LARGE_INTEGER *a, LARGE_INTEGER *b)
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
return (double)(a->QuadPart - b->QuadPart) / (double)freq.QuadPart;
}
int main()
{
char apellidos[10][10] = {"Perez", "Bartolome", "Lopez", "Gonzalez", "Jimenez", "McDonald", "Hernandez", "Pulido", "Trejo", "Cernas"};
char apellidos2[10][10] = {"Perez", "Bartolome", "Lopez", "Gonzalez", "Jimenez", "McDonald", "Hernandez", "Pulido", "Trejo", "Cernas"};
double tExeIns,tExeShe,c;
printf("Ordenamiento por Insercion\n\n");
insert(&apellidos, tExeIns);
system("pause");
return 0;
}
int compare(char *cadena1, char *cadena2)
{
int a, b;
for(a = 0; a < 10; a++)
{
if(*(cadena1 + a) > *(cadena2 + a))
{
b = 1;
return b;
}
}
return 0;
}
int insert(char *array, double *secs)
{
LARGE_INTEGER t_ini, t_fin;
QueryPerformanceCounter(&t_ini);
int i, a;
for (i=1; i < 10; i++)
{
char index[10];// = array[i];
strcpy(index, &array[i]);
a = i-1;
while (a >= 0 && compare(&array[a], index))
{
array[a + 1] = array[a];
a--;
}
strcpy(&array[a+1], index);
//array[a+1] = index;
}
QueryPerformanceCounter(&t_fin);
*secs = performancecounter_diff(&t_fin, &t_ini);
printf("%.16g milliseconds\n", *secs * 1000.0);
return 0;
}