简体   繁体   English

错误:“…”的类型冲突; 注意:之前的隐式声明“…”在这里

[英]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: 但是编译器给我以下错误:

  • SortingAlgorithmTest.c:95:8: error: conflicting types for 'useIsort' double useIsort(int arO[], int n) { ^ SortingAlgorithmTest.c:95:8:错误:'useIsort'的类型冲突double useIsort(int arO [],int n){^
  • SortingAlgorithmTest.c:77:20: note: previous implicit declaration of 'useIsort' was here double t_isort = useIsort(arrayOriginal, n); SortingAlgorithmTest.c:77:20:注意:之前'useIsort'的隐式声明是double t_isort = useIsort(arrayOriginal,n); ^ ^
  • SortingAlgorithmTest.c:112:8: error: conflicting types for 'useSsort' double useSsort(int arO[], int n) { ^ SortingAlgorithmTest.c:112:8:错误:'useSsort'的类型冲突double useSsort(int arO [],int n){^
  • SortingAlgorithmTest.c:78:20: note: previous implicit declaration of 'useSsort' was here double t_ssort = useSsort(arrayOriginal, n); SortingAlgorithmTest.c:78:20:注意:之前'useSsort'的隐式声明为double t_ssort = useSsort(arrayOriginal,n); ^ ^
  • SortingAlgorithmTest.c:129:8: error: conflicting types for 'useMsort' double useMsort(int arO[], int n) { ^ SortingAlgorithmTest.c:129:8:错误:'useMsort'的类型冲突double useMsort(int arO [],int n){^
  • SortingAlgorithmTest.c:79:20: note: previous implicit declaration of 'useMsort' was here double t_msort = useMsort(arrayOriginal, n); SortingAlgorithmTest.c:79:20:注意:之前'useMsort'的隐式声明为double t_msort = useMsort(arrayOriginal,n); ^ ^
  • SortingAlgorithmTest.c:146:8: error: conflicting types for 'useQsort' double useQsort(int arO[], int n) { ^ SortingAlgorithmTest.c:146:8:错误:“ useQsort”的类型冲突double useQsort(int arO [],int n){^
  • SortingAlgorithmTest.c:80:20: note: previous implicit declaration of 'useQsort' was here double t_qsort = useQsort(arrayOriginal, n); SortingAlgorithmTest.c:80:20:注意:之前'useQsort'的隐式声明是double t_qsort = useQsort(arrayOriginal,n); ^ ^

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.

相关问题 得到错误:“错误:&#39;call_celsius&#39;的类型冲突”和“注意:此处先前的&#39;call_celsius&#39;的隐式声明在这里” - Getting errors: “error: conflicting types for ‘call_celsius’ ” and “note: previous implicit declaration of ‘call_celsius’ was here” 错误:&#39;f&#39;的冲突类型和&#39;f&#39;的先前声明在这里 - error: conflicting types for 'f' and previous declaration of 'f' was here 类型冲突和C中的先前隐式声明 - conflicting types AND previous implicit declaration in C x的冲突类型和先前的声明在这里......什么? - Conflicting types and previous declaration of x was here…what? 注意: &#39;point_forward&#39; 的先前隐式声明在这里 - note: previous implicit declaration of ‘point_forward’ was here 以前的声明和冲突的类型 - Previous declaration and conflicting types 之前的声明-在此处和“ put_non_bloccante的类型冲突” - previous declaration of- was Here and “conflicting types for put_non_bloccante” 类型和先前的函数声明冲突? - Conflicting types and previous declaration of function? 如何在C中对函数进行排序? “先前的函数隐式声明在这里”错误 - How to sort functions in C? “previous implicit declaration of a function was here” error 运行时出错。 类型冲突和先前的声明 - error while make runs. Conflicting types and previous declaration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM