Click here to Skip to main content
15,348,965 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How do I fix the < bool PlayerDied( PlayerData * pd ) > Function?

#include <stdio.h>

int main(void) {
  printf("You will have life functions. You will get 3 lifes.\n");
char life [3];
int aa;
printf("You have 3 lifes");
printf("Press 'S' to start");

bool PlayerDied( PlayerData * pd )
    bool alive = false;
    --pd->Lives;       // player died - one less life
   return pd->Lives <= 0;
        alive = true;  // player still has a life left
    return alive;
  return 0;

What I have tried:

Hi This is for a text rpg I think
Updated 18-Mar-21 22:49pm
Richard MacCutchan 19-Mar-21 5:55am
What is the problem that prevents you going and actually learning the language that you are trying to use?

You could try reading what was written where you got that code :

BTW - I don't think C has a boolean type so you can define one for yourself, along with true and false values.
You also need to define a PlayerData structure.

I will repeat myself, you need to define a PlayerData structure. If you are not ready to define and use data structures then you should not use that function and you should step back and learn the language more thoroughly. The alternative is to a use pile of global variables and that is a terrible idea.
To add to what Rick says, C does not support nested functions - you cannot define your PlayerDied function inside the body of the main function.
And defining a function does not mean it gets executed - you have to call it in order to use it.

You need to learn the basics rather than copy'n'paste'n'guess: it'll be a lot quicker in the long run!
Try, for instance:
#include <stdio.h>
#include <stdbool.h>

typedef struct
  // other fields here
  int lives;
} PlayerData;

bool player_died( PlayerData * pd );

int main(void)
  int iteration = 0;

  printf("You will have life functions. You will get 3 lifes.\n");

  PlayerData pd = {3};

  while ( ! player_died(&pd))
    printf("iteration %d, the player is still alive\n", iteration);
  printf("the player eventually died\n");

  return 0;

bool player_died( PlayerData * pd )
  if ( pd->lives )
    return false;
  return true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900