-1

I'm trying to create a programm to add, exclude and print state, city name, total population, men population, women population, mens percentage and womens percentage. I Keep getting this damn error:

error: (on the 60th line)'Chart' undeclared (first use in this function)

#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");
            }
        }
    }
}
  • http://stackoverflow.com/questions/1675351/typedef-struct-vs-struct-definitions you need a typedef of you need to specify struct everywhere you have definitions of Chart – Mircea May 22 '15 at 17:48
  • don't reuse identifiers... `list` is local variable, a global function name, an argument to the very same function... holy crap! – Diego May 22 '15 at 17:50

2 Answers2

1

struct Chart is a type. You cannot write to a type. You need to declare a variable of this type, and then write it:

struct Chart
{
....
} chart; // <-- This is your variable name
Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
1
struct Chart
{
//something
};

creates a user-defined data type. A data type cannot have a value. You need to have a variable of that type to put some value into it.

So, you need to define a variable of that type to use it, like

struct Chart Chart[10];

and then, you can use like

Chart[j].mu = .....
Natasha Dutta
  • 3,242
  • 21
  • 23