函数类型冲突错误,求求大佬指点!!!
#include <stdio.h>#include <stdlib.h>
#include <time.h>
void bogo_sort(int, int);
int array;
void bogo_sort(int a[], int length)
{
int temp, i, index;
srand(time(NULL));
for (i = 0; i < length; i++)
{
index = rand() % (length - i) + i;
if (index != i)
{
temp = a;
a = a;
a = temp;
}
if(i == length - 1)
{
if((a == 67 && a == 70) && (a == 73 && a == 101))
if((a == 104 && a == 105) && (a == 108 && a == 111))
break;
}
}
}
int main()
{
int array[] = {73, 108, 111, 118, 101, 70, 105, 104, 67};
int i, length;
time_t begin, end;
begin = time(NULL);
length = sizeof(array) / sizeof(array);
bogo_sort(array, length);
printf("排序后的结果是:");
for (i = 0; i < length; i++)
{
printf("%d ", array);
}
putchar('\n');
end = time(NULL);
printf("总共耗时:%ld秒\n", end - begin);
return 0;
}
这个代码在第9行报错:9 6 D:\FishC\S1E32\test0.c conflicting types for 'bogo_sort'
但是我不明白我已经声明函数bogo_sort是void类型的,为什么还会冲突呢? #include <stdio.h>
#include <stdlib.h>
#include <time.h>
//void bogo_sort(int, int);
void bogo_sort(int*, int);
int array;
void bogo_sort(int a[], int length)
{
int temp, i, index;
srand(time(NULL));
for (i = 0; i < length; i++)
{
index = rand() % (length - i) + i;
if (index != i)
{
temp = a;
a = a;
a = temp;
}
if(i == length - 1)
{
if((a == 67 && a == 70) && (a == 73 && a == 101))
if((a == 104 && a == 105) && (a == 108 && a == 111))
break;
}
}
}
int main()
{
int array[] = {73, 108, 111, 118, 101, 70, 105, 104, 67};
int i, length;
time_t begin, end;
begin = time(NULL);
length = sizeof(array) / sizeof(array);
bogo_sort(array, length);
printf("排序后的结果是:");
for (i = 0; i < length; i++)
{
printf("%d ", array);
}
putchar('\n');
end = time(NULL);
printf("总共耗时:%ld秒\n", end - begin);
return 0;
}
去掉第五行就好了啊
页:
[1]