C programming error: [undefined reference to: 'show_record']

C programming error: [undefined reference to: 'show_record']

我从网上获取了代码 http://www.codewithc.com/quiz-game-mini-project-in-c/,但我在代码中遇到了错误,所以我删减了代码。我遇到错误 [undefined reference to: 'show_record'] 我无法解决。任何有关如何解决此问题的帮助或建议将不胜感激。

这是代码片段:

#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();
    }

}

您在 main 中实现了 show_record(),这是不允许的。 show_record() 需要在 main.

之外声明的全局范围内实现