[英]error: conflicting types for '…'; note: previous implicit declaration of '…' was here
I created a file. 我创建了一个文件。 C "Sorting.c" that implements several algorithms for sorting an array of integers.
C“ Sorting.c”实现几种用于对整数数组进行排序的算法。 Now I have to create a test file that creates random array and performs the various sorting algorithms on these arrays random.
现在,我必须创建一个测试文件,该文件创建随机数组并在这些数组上随机执行各种排序算法。 Moreover, the time resulting must be written on the terminal and on a text file.
此外,所产生的时间必须写在终端和文本文件上。
I wrote this code: 我写了这段代码:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <sys/time.h>
#include "Sorting.h" //file thath contains the implementation of the sorting method like iinsertion sort, selection sort, merge sort and quick sort
#define N 100
#define STEP 5
int arrayOriginal[N];
int arrayToSort[N];
int arrayTemp[N];
void fillArray(int a[], int n, int max) {
srand(time(NULL));
int i;
for(i = 0; i < n; i++)
a[i] = rand() % max;
}
void copyInto(int a[], int b[], int n) {
int i;
for(i = 0; i < n; i++)
b[i] = a[i];
}
void testReport() {
FILE* pFile = fopen("Times.txt", "a");
int n;
for(n = STEP; n < N; n += STEP) {
fillArray(arrayOriginal, n, 9*n/10);
double t_isort = useIsort(arrayOriginal, n);
double t_ssort = useSsort(arrayOriginal, n);
double t_msort = useMsort(arrayOriginal, n);
double t_qsort = useQsort(arrayOriginal, n);
fprintf(pFile, "Size = %d, t_isort = %.6f, t_ssort = %.6f, t_msort = %.6f, t_qsort = %.6f \n", n, t_isort, t_ssort, t_msort, t_qsort);
printf("Size = %d, t_isort = %.6f, t_ssort = %.6f, t_msort = %.6f, t_qsort = %.6f \n", n, t_isort, t_ssort, t_msort, t_qsort);
}
printf("\n\n");
fclose(pFile);
}
double useIsort(int arO[], int n) {
copyInto(arO, arrayToSort, n);
struct timeval t1, t2;
gettimeofday(&t1, NULL);
isort(arrayToSort, n);
gettimeofday(&t2, NULL);
double timediff = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
timediff += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
return timediff;
}
double useSsort(int arO[], int n) {
copyInto(arO, arrayToSort, n);
struct timeval t1, t2;
gettimeofday(&t1, NULL);
ssort(arrayToSort, n);
gettimeofday(&t2, NULL);
double timediff = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
timediff += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
return timediff;
}
double useMsort(int arO[], int n) {
copyInto(arO, arrayToSort, n);
struct timeval t1, t2;
gettimeofday(&t1, NULL);
msort(arrayToSort, n);
gettimeofday(&t2, NULL);
double timediff = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
timediff += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
return timediff;
}
double useQsort(int arO[], int n) {
copyInto(arO, arrayToSort, n);
struct timeval t1, t2;
gettimeofday(&t1, NULL);
qisort(arrayToSort, n);
gettimeofday(&t2, NULL);
double timediff = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
timediff += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
return timediff;
}
int main() {
testReport();
return 0;
}
But the compiler gives me the following errors: 但是编译器给我以下错误:
I think it's a stupid mistake, but I think that is an hour and I can not find the error. 我认为这是一个愚蠢的错误,但我认为这是一个小时,我找不到错误。 Can anyone help me?
谁能帮我? Thanks
谢谢
In C, when you call a function, its definition must be above the caller function. 在C中,当您调用函数时,其定义必须在调用者函数之上。
Try to put your use*sort above testReport(), it should fix your problem. 尝试将您的use * sort放在testReport()上方,它应该可以解决您的问题。
You may also copy all the function definitions into your .h if you don't want to mind about the order of your functions. 如果您不介意函数的顺序,也可以将所有函数定义复制到.h中。
在testReport中使用函数之前,请声明它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.