Hi,

I have a counter that I am using in my main and increasing through pointers in other functions. I want to be able to use the value of this counter in a loop but... I can't. I am getting a warning when I compile saying that I am trying to make a comparison between a pointer and an integer.

How can I get access to this variable? I am new to c and adding pointers into the mix is really messing with me!

Here is a snippit of my code:

Structures and in the main:

typedef struct {
        char    name[MAX_SIZE];
        int     district;
        int     yearOfBirth;
        char    gender;
}Citizen;

typedef struct {
        Citizen person;
        int     yearOfGame;
        int     trainingScore;
}Tribute;

typedef struct {
        Tribute  tributes[24];
        int      yearOfGame;
        int      victor;
}Game;

void mainMenu(Citizen*, Game*, int*, int*);
void dataMenu(Citizen*, Game*, int*, int*);
void generateReportsMenu();
void panemCitizenData(Citizen*, int*);
void hungerGamesData(Citizen*, Game*, int*, int*);
void ascendingOrderByVictor();
void descendingOrderByTraining();
void descendingOrderByVictor();
void ascendingOrderByDistrict();

int main() {

        Game                    games[100];
        Citizen                 citizens[1000];
        int sizeOfCitizens      = 0;
        int sizeOfGames         = 0;
        mainMenu(citizens, games, &sizeOfCitizens,  &sizeOfGames);

        return 0;
}

and the function I am trying to use sizeOfGames in (where it is called gsize_ptr:

void descendingOrderByTraining(Citizen *c_ptr, Game *g_ptr, int *citsize_ptr, int *gsize_ptr){
        int i;

        printf("These are all of the citizens names: \n");
        for (i = 0; i < gsize_ptr; i++){
                printf("%s\n", g_ptr->tributes[i].person.name);
        }


}

Any help would be greatly appreciated

for (i = 0; i < gsize_ptr; i++){

gsize_ptr is a pointer, you need to dereference it:

for (i = 0; i < *gsize_ptr; i++){

Of course, looking at that function definition I see no reason why gsize_ptr needs to be a pointer in the first place, unless that's not the final definition and you plan to ultimately assign a value to sizeOfGames from descendingOrderByTraining().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.