2016-07-13 13 views
0

オンラインhttp://www.codewithc.com/quiz-game-mini-project-in-c/からコードを取得しましたが、コードにエラーが発生しました。私はエラーが発生しました[未定義の参照: 'show_record']私は解決できません。この問題を解決する方法についての助言や提案は非常に高く評価されます。ここでCプログラミングエラー:[未定義の参照: '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(); 
    } 

} 
+0

1.関数内の関数定義はGCC拡張であり、必要でない限り使用しないでください。 2. '&* name'は単に' name'と書くことができます – MikeCAT

+4

あなたのインデントが悪いのでここには表示されませんが、あなたは 'show_record()' *を別の関数main 。あなたは標準Cでそれを行うことはできません(私はちょうどこれをより明白にするためにあなたのインデントを更新しました)。 – lurker

+1

最後の中括弧を 'void show_record()'行の前に移動します。これで問題は解決するはずです。 – dasblinkenlight

答えて

3

あなたが許可されていないmain内部show_record()を実装しました。 show_record()は、mainの外部に宣言されたグローバルスコープで実装する必要があります。