c - C 中烦人的结构错误

标签 c struct charts

我正在尝试创建一个程序来添加、排除和打印州、城市名称、总人口、男性人口、女性人口、男性百分比和女性百分比。我不断收到这个该死的错误:

错误:(第 60 行)“图表”未声明(在此函数中首次使用)

#include<stdio.h>
#include<string.h>
struct Chart
{
    char uf[3]; // refers to state
    char ct[100]; // refers to city
    float pop;  // refers to population
    float h;  // refers to mens pop
    float m; // refers to womens pop
    float ph; // refers to percentage of men in the given city
    float pm; // refers to percentage of women in the given city
};
void Cad(struct Tabela vet[], int n); /* register function */
void exc(struct Tabela vet[], int n); /* exclude function*/
void list(struct Tabela vet[], float min, float max, char list); /* print function*/
int main()
{

    int n; /* number of lines to add or remove*/
    char c,list; /* c is the choice of the user (remove,add,print) and list is for the list function*/
    float max, min; /* parameters for list function*/
    struct Tabela vet[1000]; /* initializing struct */

    scanf(" %c",&c); /* User choice.*/


    while((c !='f') && (c!='F')) /* programm keep running til f or F is pressed*/
    {
        if((c=='c') || (c=='C')) /* register func */
        {
            scanf("%d",&n); /*number of lines to add*/
            Cad(vet, n);
        }
        else if((c=='e') || (c == 'E')) /*remove func*/
        {
            scanf("%d",&n); /* number of lines to remove*/
            exc(vet,n);

        }
        else if((c=='l') || (c == 'L')) /*print func*/
        {
            scanf(" %c",&list); /* print based on men, women or population choice*/
            scanf("%f %f",&min, &max); /*minimum and maximum values to be printed */
            list(vet, min, max , list); 
        }
            else
            {
                printf("Invalid command. Press 'F' to terminate.\n");
            }
            return 0;
        }
    return 0;
}
void Cad(struct Tabela vet[], int n)
{
    int i,j;
    for(i=j=0; i<n; j++)
    {
        if(Chart[j].mu ==0) /* if the position is free, it is going to be filled*/
        {
            scanf("%s",vet[j].uf); // filling positions
            scanf("%s",vet[j].ct;
            scanf("%f",&vet[j].pop);
            scanf("%f",&vet[j].h);
            scanf("%f",&vet[j].m);
            scanf("%f",&vet[j].ph);
            scanf("%f",&vet[j].pm);
            i++;
        }
    }
}
void exc(struct Tabela vet[], int n)
{
    int i,j;
    char excCt[100], excUf[3]; /*The data is erased based on the State and city name */
    for(i=0; i<n; i++)
    {
        scanf("%s",excUf);
        scanf("%s",excCt);
        for(j=0; j<1000; j++)
        {
            if(strcmp(excUf,vet[j].uf)==0)
            {
                if(strcmp(excCt,vet[j].ct)==0)
                {
                    vet[j].h = 0;
                    vet[j].m = 0;
                    vet[j].ph = 0;
                    vet[j].pm = 0;
                    break;
                }
            }
        }
    }
}
void list(struct Tabela vet[], float min, float max, char list)
{
    int i;
    if((list == 'H') || (list == 'h')) // user choice is men
    {
        for(i=0; i<1000; i++)
        {
            if((vet[i].homens>=min) && (vet[i].homens<=max)) /* if the pop of men is higher than the minimum value and lower then the maximum, the line is printed */
            {
                printf("%s ,",vet[i].uf);
                printf("%s ,",vet[i].ct);
                printf("%.0f ,",vet[i].pop);
                printf("%.0f ,",vet[i].h);
                printf("%.0f ,",vet[i].m);
                printf("%.1f ,",vet[i].ph);
                printf("%.1f",vet[i].pmu);
                printf("\n");
            }
        }
    }
    else if((list == 'M') || (list == 'm')) // user choice is women
    {
        for(i=0; i<1000; i++)
        {
            if((vet[i].mulheres>=min) && (vet[i].mulheres<=max))
            {
                printf("%s ,",vet[i].uf);
                printf("%s ,",vet[i].municipio);
                printf("%.0f ,",vet[i].pop);
                printf("%.0f ,",vet[i].homens);
                printf("%.0f ,",vet[i].mulheres);
                printf("%.1f ,",vet[i].phomem);
                printf("%.1f",vet[i].pmulher);
                printf("\n");
            }
        }
    }
    else if((list == 'P') || (list == 'p')) /* user choice is absolute population */
    {
        for(i=0; i<1000; i++)
        {
            if((vet[i].pop>=min) && (vet[i].pop<=max))
            {
                printf("%s ,",vet[i].uf);
                printf("%s ,",vet[i].ct);
                printf("%.0f ,",vet[i].pop);
                printf("%.0f ,",vet[i].h);
                printf("%.0f ,",vet[i].m);
                printf("%.1f ,",vet[i].ph);
                printf("%.1f",vet[i].pm);
                printf("\n");
            }
        }
    }
}

最佳答案

struct Chart
{
//something
};

创建用户定义的数据类型。数据类型不能有。您需要有一个该类型的变量来为其添加一些值。

因此,您需要定义该类型的变量才能使用它,例如

struct Chart Chart[10];

然后,你可以使用像

Chart[j].mu = .....

关于c - C 中烦人的结构错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30402875/

相关文章:

c - 阿姆斯壮数程序中的逻辑错误

c - 为什么在下面的编程中结构显示的内存比实际内存少

c# - 当传递给结构中的非托管代码时,C# 中的字节数组会发生什么情况?

javascript - 使用 Highcharts 创建 marimekko 图表

asp.net - 在鼠标悬停的堆叠栏中显示所有系列的值(ASP.NET CHART)

c - 发出信号并杀死 C

c - C 中的混合指针、数组和函数类型声明

c - 它被认为是全局变量吗?结构和链表

C++ 将派生结构传递给需要超结构的方法

javascript - d3.js 比特币图表形状错误