Race simulator help: not printing name or color

As said in the title, the driver’s name and car color are left blank when I run the code.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Structures section
struct Race {
  int numberOfLaps;
  int currentLap;
  char* firstPlaceDriverName;
  char* firstPlaceRaceCarColor;

struct RaceCar {
  char* driverName;
  char* raceCarColor;
  int totalLapTime;

// Print functions section
void printIntro() {
  printf("Welcome to our main event digital race fans!\nI hope everybody has their snacks because we are about to begin!\n");

void printCountDown() {
  printf("Racers Ready!\n5...\n4...\n3...\n2...\n1...\nRace!\n");

void printFirstPlaceAfterLap(struct Race race) {
  printf("After lap %i\nFirst place is: %s in the %s race car!\n", race.currentLap, race.firstPlaceDriverName, race.firstPlaceRaceCarColor);

void printCongratulation(struct Race race) {
  printf("Let's all congratulate %s in the %s race car for an amazing performance!\nIt truly was a great race and everybody have a goodnight!\n", race.firstPlaceDriverName, race.firstPlaceRaceCarColor);

// Logic functions section
int calculateTimeToCompleteLap() {
  int speed = (rand() % 3) + 1;
  int acceleration = (rand() % 3) + 1;
  int nerves = (rand() % 3) + 1;

  return speed + acceleration + nerves;

void updateRaceCar(struct RaceCar* raceCar) {
  raceCar->totalLapTime += calculateTimeToCompleteLap();

void updateFirstPlace(struct Race* race, struct RaceCar* raceCar1, struct RaceCar* raceCar2) {
  if (raceCar1->totalLapTime <= raceCar2->totalLapTime)
    race->firstPlaceDriverName = raceCar1->driverName;
    race->firstPlaceRaceCarColor = raceCar1->raceCarColor;
    race->firstPlaceDriverName = raceCar2->driverName;
    race->firstPlaceRaceCarColor = raceCar2->raceCarColor;

void startRace(struct RaceCar* raceCar1, struct RaceCar* raceCar2) {
  struct Race race = {5, 1, "", ""};

  for(int i = 0; i < race.numberOfLaps; i++) {

int main() {
  struct RaceCar raceCar1 = {"Mike", "green", 0};
  struct RaceCar raceCar2 = {"Ellen", "purple", 0};
  startRace(&raceCar1, &raceCar2);

What have I done wrong?

Haven’t looked through it all. Just a cursory look, so there may or may not be other issues.

You have a function updateFirstPlace, but you haven’t made a call to this function anywhere in your code.

You have a function updateFirstPlace, but you haven’t made a call to this function anywhere in your code.

That fixed it, thanks! :slight_smile:

1 Like