如何修复 C3861:“...”:找不到标识符 [重复]

Posted

技术标签:

【中文标题】如何修复 C3861:“...”:找不到标识符 [重复]【英文标题】:How to fix C3861: '...': identifier not found [duplicate] 【发布时间】:2019-06-02 13:24:33 【问题描述】:

我想使用 Visual Studio 创建一个游戏扫雷。项目视觉 c++ Win32 控制台应用程序。源文件 C++ 文件(.cpp) 这是我的源代码

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <conio.h>
#include <time.h>

int menu()//menampilkan menu

    int x;
    printf("\nThe Minesweeper for You\n\n");
    printf("<<Main Menu>>\n\n");
    printf("1.Start\n");
    printf("2.Exit\n\n");
    printf("Masukkan pilihan : ");
    scanf("%i", &x);
    while ((x<1) || (x>2))
    
        printf("Pilihan Invalid !\n");
        printf("Masukkan pilihan : \n");
        scanf("%i", &x);
    
    printf("\n");
    return x;


void cek(int board[15][15], int revealed[15][15], int x, int y)//mengecek saat board[x][y] berisi 0

    //Kamus lokal
    int i, j;
    revealed[x][y] = 1;

    //Algoritma
    for (i = x - 1; i<x + 2; i++)
    
        for (j = y - 1; j<y + 2; j++)
        
            if (i >= 0 && j >= 0 && i<15 && j<15)
            
                if (revealed[i][j] == 0 && board[i][j] != 0)
                
                    revealed[i][j] = 1;
                
            
        
    
    for (i = x - 1; i<x + 2; i++)
    
        for (j = y - 1; j<y + 2; j++)
        
            if (i >= 0 && j >= 0 && i<15 && j<15)
            
                if (revealed[i][j] == 0 && board[i][j] == 0)
                
                    cek(board, revealed, i, j);
                
            
        
    






int klik(int board[15][15], int revealed[15][15], char kondisi[15][15])

    //Kamus lokal
    int a, b, x, y, q, z;

    //Algoritma
    do 
        printf("X: ");
        scanf("%i", &y);
        printf("y: ");
        scanf("%i", &x);
     while (x<1 || y<1 || x>15 || y>15);

    x--; y--;//konfersi ke matriks yg dari 0 sampai 14
    if (kondisi[x][y] == 'F')
    
    
    else if (board[x][y] == 9)
    
        for (a = 0; a<15; a++)for (b = 0; b<15; b++)
        
            if (board[a][b] == 9)revealed[a][b] = 1;
        
        z = 1;

    
    else if (board[x][y] == 0)
    
        revealed[x][y] = 1; //revealed 1 terbuka
        cek(board, revealed, x, y);
    
    else revealed[x][y] = 1; 

    for (a = 0; a<15; a++)
    
        for (b = 0; b<15; b++)
        if (revealed[a][b] == 1)
        
            switch (board[a][b])
            
            case 0: kondisi[a][b] = '0'; break;
            case 1: kondisi[a][b] = '1'; break;
            case 2: kondisi[a][b] = '2'; break;
            case 3: kondisi[a][b] = '3'; break;
            case 4: kondisi[a][b] = '4'; break;
            case 5: kondisi[a][b] = '5'; break;
            case 6: kondisi[a][b] = '6'; break;
            case 7: kondisi[a][b] = '7'; break;
            case 8: kondisi[a][b] = '8'; break;
            case 9: kondisi[a][b] = '#'; break;
            

        

    

    q = jumlhbuka(revealed, kondisi);

    if (z == 1) return 1; 
    else if (q >= 200) z = 2; 
    else z = 0; 
    return z;



int jumlhbuka(int revealed[15][15], char kondisi[15][15])

    int a, b, q = 0;
    for (a = 0; a<15; a++)
    
        for (b = 0; b<15; b++)
        
            if (revealed[a][b] == 1 && kondisi[a][b] != '#') q = q + 1; 
        
    
    return q;



void flag(char kondisi[15][15], int revealed[15][15])

    //Kamus lokal
    int x, y;
    //Algoritma
    do 
        printf("X: ");
        scanf("%i", &y);
        printf("y: ");
        scanf("%i", &x);
     while (x<1 || y<1 || x>15 || y>15);
    if (revealed[x - 1][y - 1] == 0)//board = 0 tertutup
    
        kondisi[x - 1][y - 1] = 'F';

    


void rflag(char kondisi[15][15], int revealed[15][15])

    //Kamus lokal
    int x, y;

    //Algoritma
    do 
        printf("X: ");
        scanf("%i", &y);
        printf("y: ");
        scanf("%i", &x);
     while (x<1 || y<1 || x>15 || y>15);

    if (kondisi[x - 1][y - 1] == 'F')       //jika kondisinya sedang flag
    
        kondisi[x - 1][y - 1] = '_';
    


void random(int A[15][15])

    //Kamus lokal
    srand((unsigned)time(NULL));
    int a, b, c = 0;

    //Algoritma
    for (a = 0; a<15; a++) for (b = 0; b<15; b++) A[a][b] = 0;  
    while (c<25)
    
        for (a = 0; a<15 && c<25; a++)
        
            for (b = 0; b<15 && c<25; b++)
            
                if (A[a][b] != 9)
                
                    A[a][b] = rand() % 10;
                    if (A[a][b] == 9) c++; 
                    else A[a][b] = 0; 
                
            
        
    



void PasangBom(int board[15][15])//mengisi board dengan 0-9. 9 maka berisi bom dan 0 maka kosong

    //Kamus lokal
    int x, y, a, i, j; a = 25;

    //Algoritma
    random(board);//isi board dengan 9 sebagai bom dan yang lain 0;
    for (x = 0; x<15; x++)
    for (y = 0; y<15; y++)
    if (board[y][x] == 9)
    
        if ((y - 1) >= 0)
        if (board[y - 1][x] != 9)
            board[y - 1][x]++;
        if ((y - 1) >= 0 && (x - 1) >= 0)
        if (board[y - 1][x - 1] != 9)
            board[y - 1][x - 1]++;
        if ((x - 1) >= 0)
        if (board[y][x - 1] != 9)
            board[y][x - 1]++;
        if ((y + 1) < 15)
        if (board[y + 1][x] != 9)
            board[y + 1][x]++;
        if ((y + 1) < 15 && (x + 1) < 15)
        if (board[y + 1][x + 1] != 9)
            board[y + 1][x + 1]++;
        if ((x + 1) < 15)
        if (board[y][x + 1] != 9)
            board[y][x + 1]++;
        if ((y - 1) >= 0 && (x + 1) < 15)
        if (board[y - 1][x + 1] != 9)
            board[y - 1][x + 1]++;
        if ((y + 1) < 15 && (x - 1) >= 0)
        if (board[y + 1][x - 1] != 9)
            board[y + 1][x - 1]++;
    





void Tampilkar(char x[15][15])

    //Kamus lokal
    int a = 0;
    int b = 0;

    //Algoritma
    printf(" y\\x");
    while (b<15)
    
        if (b<9) printf("_%i__", b + 1); 
        else printf("%i__", b + 1); 
        b = b + 1;
    
    printf("\n");
    while (a<15)
    
        b = 0;
        if (a<9) printf(" %i", a + 1); 
        else printf("%i", a + 1); 
        while (b<15) printf("_|_%c", x[a][b]); b = b + 1; 
        printf("_|\n");
        a = a + 1;
    
    printf("\n");


void Tampilang(int x[15][15])

    //Kamus lokal
    int a = 0;
    int b = 0;

    //Algoritma
    printf(" y\\x");
    while (b<15)
    
        if (b<9) printf("_%i__", b + 1); 
        else printf("%i__", b + 1); 
        b = b + 1;
    
    printf("\n");
    while (a<15)
    
        b = 0;
        if (a<9) printf(" %i", a + 1); 
        else printf("%i", a + 1); 
        while (b<15) printf(" | %i", x[a][b]); b = b + 1; 
        printf(" |\n");
        a = a + 1;
    
    printf("\n");


void start()

    //Kamus lokal
    int a, b, x, y, z, jbuka;
    int jk = 0;//jumlah klik,
    int dead = 0;//0 masih main, 1 kalah, 2 menang , 4 keluar(stop)
    int board[15][15];
    int revealed[15][15];
    char kondisi[15][15];

    //Algoritma
    PasangBom(board);
    for (a = 0; a<15; a++)for (b = 0; b<15; b++)revealed[a][b] = 0;//mengkosongkan parameter buka
    for (a = 0; a<15; a++)for (b = 0; b<15; b++)kondisi[a][b] = '_';//mengkosongkan tampilan awal
    Tampilkar(kondisi);
    while (dead == 0)
    
        do
            printf("1.Klik\n");
            printf("2.Flag\n");
            printf("3.Remove Flag\n");
            printf("4.Stop\n");
            printf("Masukkan pilihan : ");
            scanf("%i", &z);
         while (z<1 || (z>4 && z != 2357));
        switch (z)
        
        case 1:
            dead = klik(board, revealed, kondisi);
            jk++;
            break;

        case 2:
            flag(kondisi, revealed);
            jk++;
            break;

        case 3:
            rflag(kondisi, revealed);
            jk++;
            break;

        case 4:
            system("cls");
            dead = 4;
            break;

        case 2357: //Cheat untuk melihat seluruh isi bom di minesweeper bila user memasukkan angka 2357
            Tampilang(board);
            break;
        
        if (z != 4)
            Tampilkar(kondisi);
    


    jbuka = jumlhbuka(revealed, kondisi);
    if (dead == 1)
    
        printf("\nANDA MENGENAI BOMB!!! \n\n");
    
    else if (dead == 2)
    
        printf("\nANDA MENANG!!! :)\n\n");

    

    system("cls");




int main()

    int a, x;
    a = 1;

    while (a == 1)
    
        printf("========================================\n");
        printf("  #     # # #   # ##### ##### SWEEPER\n");
        printf("  ##   ## # ##  # #     #     SWEEPER\n");
        printf("  # # # # # # # # ##### ##### SWEEPER\n");
        printf("  #  #  # # #  ## #         # SWEEPER\n");
        printf("  #     # # #   # ##### ##### SWEEPER\n");
        printf("========================================\n\n");
        x = menu();
        switch (x)
        case 1:
            system("cls");
            start();
            break;

        case 2:
            system("cls");
            a = 0;
            printf("\nThanks for Playing Our Game!!!\n\n");
        
    

我得到了这个错误 错误 C3861:“jumlhbuka”:未找到标识符 我尝试使用谷歌搜索如何修复 C3861 并尝试解决方案仍然失败:( 请帮我解决它,我希望有人能解决它 谢谢大家:)

【问题讨论】:

int jumlhbuka(int revealed[15][15], char kondisi[15][15]);放在int klik(int board[15][15], int revealed[15][15], char kondisi[15][15]) 上面 或将jumlhbuka的定义移到klik的定义之前 我认为我们可以关闭题外话“简单的印刷错误”。 @Fahim10969 这完全是一个不同的错误。 @Chipster 我不认为,只是将定义移到另一个定义之前或添加声明并不复杂 【参考方案1】:

只需将函数的原型行添加到文件顶部即可:

int jumlhbuka(int revealed[15][15], char kondisi[15][15]);

这样,它可以在实际执行之前找到jumlhbuka()。总之,它看起来像这样:

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <conio.h>
#include <time.h>

// added line. Should do the trick
int jumlhbuka(int revealed[15][15], char kondisi[15][15]);

int menu()//menampilkan menu

// ...

或者,您也可以切换jumlhbuka()klik() 的顺序。

【讨论】:

以上是关于如何修复 C3861:“...”:找不到标识符 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

C++ Visual Studio 2012 错误 C3861:'_T':找不到标识符?

error C3861: “maxmin”: 找不到标识符

错误 C3861:“execute_assert”:找不到标识符

error C3861: “getpid”: 找不到标识符

error C3861: "max": 找不到标识符

在win7上用cygwin编译Geant4自带的example提示 error C3861: “lrint”: 找不到标识符