-1

I took code from online http://www.codewithc.com/quiz-game-mini-project-in-c/ and I was getting errors in the code, so I cut down the code. I am getting an error [undefined reference to: 'show_record'] I cannot solve. Any help or suggestions on how to solve this issue would be greatly appreciated.

Here is a snippet of the code:

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

void show_record();
void reset_score();
void help();
void edit_score(float, char[]);
int main()
{
    int countr, r, r1, count, i, n;
    float score;
    char choice;
    char playername[20];

  mainhome:
    system("clear");
    printf("\n\t\t\t   WELCOME ");
    printf("\n\t\t\t    to ");
    printf("\n\t\t\t   THE GAME ");
    printf("\n\t\t > Press S to start the game");
    printf("\n\t\t > Press V to view the highest score  ");
    printf("\n\t\t > Press R to reset score");
    printf("\n\t\t > press H for help           ");
    printf("\n\t\t > press Q to quit            ");
    printf("\n\t\t________________________________________\n\n");

    choice = toupper(getchar());
    if (choice == 'V')
    {
        show_record();
        goto mainhome;
    }

    void show_record()
    {
        system("clear");
        char name[20];
        float scr;
        FILE *f;

        f = fopen("score.txt", "r");
        fscanf(f, "%s%f", &*name, &scr);
        printf("\n\n\t\t*************************************************************");
        printf("\n\n\t\t %s has secured the Highest Score %0.2f", name, scr);
        printf("\n\n\t\t*************************************************************");
        fclose(f);
        getchar();
    }

}
alk
  • 69,737
  • 10
  • 105
  • 255
user1049876
  • 117
  • 1
  • 3
  • 18
  • 1. Defining functions inside functions is GCC extension and it shouldn't be used unless it is necessary. 2. `&*name` can simply be written as `name` – MikeCAT Jul 13 '16 at 15:59
  • 4
    Your indentation is poor, so it's not visible here, but you just tried to declare a function `show_record()` *inside* of another function, `main`. You can't do that in standard C. (I just updated your indentation to make this more evident). – lurker Jul 13 '16 at 15:59
  • 1
    Move the last curly brace to before `void show_record()` line. This should fix the problem. – Sergey Kalinichenko Jul 13 '16 at 16:01

1 Answers1

3

You've implemented show_record() inside main, which isn't allowed. show_record() needs to be implemented in the global scope where it was also declared, outside of main.

alter_igel
  • 6,899
  • 3
  • 21
  • 40