C语言 从不兼容的指针类型传递“”的参数 1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20452523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:28:34  来源:igfitidea点击:

passing argument 1 of " " from incompatible pointer type

cpointersstructure

提问by Fran

I have three warnings on my program.

我的程序有三个警告。

First:

第一的:

passing argument 1 of " " from incompatible pointer type at line 18 and assigment makes integer from pointer without a cast at line 37
passing argument 1 of " " from incompatible pointer type at line 18 and assigment makes integer from pointer without a cast at line 37

Here is my program:

这是我的程序:

#include <stdio.h>


struct Equipo {
   char nombre [20];
   int goles[7];
};
struct Equipo resultados [6];

void LeerFich(struct Equipo *resultados);

void main()
{
    struct Equipo *equipos;
    LeerFich(&equipos);    //warning here
    Buscar(equipos);
    MarcaCero(equipos);
}

//Funciones

void LeerFich(struct Equipo *resultados)
{
    FILE *F;
    F= fopen("C:\Users\Paco\Downloads\datosLiga.txt", "r");
    fgets(resultados->nombre, 20, F);
    fscanf(F, "%d", &resultados->goles);
    fclose(F);
}
int Buscar(struct Equipo resultados[6], int v[6])
{
    int i, *maximo, sum, *equipo, t=6;
    for(i=0; i<6; i++){
        sum += resultados[i].goles;      //warning here
        if(resultados[i].goles>maximo)
            maximo=resultados[i].goles;
            *equipo=i;
    }
    while(i<t && v[i]!=*equipo)
        i++;
    if(i==t)
        printf("el equipo es: %s\n", resultados[*equipo].nombre);
        printf("ha marcado %d goles\n", *maximo);
}
int MarcaCero(struct Equipo resultados[6])
{
    int i, v[6];
    for(i=0; i<6; i++){
        if(resultados[i].goles[0]==0 && resultados[i].goles[7]==0)
            i=v[i];
    }
    for(i=0; i<6; i++)
        printf("\nel equipo %s no marco", resultados[v[i]].nombre);
}

回答by ouah

Replace

代替

LeerFich(&equipos);    //warning here

by

经过

LeerFich(equipos);

equiposis already of type struct Equipo *, there is no need to take its address.

equipos已经是 type struct Equipo *,就不需要取它的地址了。

回答by Kaustav Ray

LeerFich(&equipos); 

here you are sending the address of the pointer variable which can not be received by the declaration

在这里,您正在发送声明无法接收的指针变量的地址

Use : LeerFich(equipos);

用 : LeerFich(equipos);