what's the number of times the letter "{" appears in:
q: необработанное исключение по адресу 0x003230ad в consoleapplication.exe: 0xc0000005: нарушение прав доступа при чтении по адресу 0xfdfdfe05 подскажите, что именно может вызывать ошибку и как ее исправить? visual studio пишет, что проблемы не найдены, но возникает исключение когда программа проходит несколько циклов или если компьютер играет то сразу же. если не использовать указатели, такой проблемы не возникает.
код программы:
#include <iostream>
#include <time.h>
using namespace std;
int buf1, buf2, n, m;
void rnd(int**, int*);
void ar(int**);
void ved(int**, int**);
void pkved(int**, int**);
int sw(int**, int**, int);
int main()
{
    srand(time(0));
    cout << "\t*** created by me (lena nemtsova) ***\n\n";
    cout << "puzzle game\n";
    cout << "*********************************************\n";
    int ch, l = 1;
    while (l != 0)
    {
        cout << "choose game options:\n1. 8 (3x3)\n2. 15 (4x4)\n";
        cin >> ch;
        switch (ch)
        {
        case 1: m = 3; n = 8; l = 0; break;
        case 2: m = 4; n = 15; l = 0; break;
        default: cout << "error!" << endl;
        }
    }
    int** a = new int* [m]; for (int i = 0; i < m; i++) a[i] = new int[m];
    int** a1 = new int* [m]; for (int i = 0; i < m; i++) a1[i] = new int[m];
    int* n1 = new int[n]; for (int i = 0; i < n; i++) n1[i] = i + 1;
    rnd(a1, n1);
    for (int i = n - 1; i >= 0; i--)
    {
        buf1 = rand() % (i + 1); buf2 = n1[i]; n1[i] = n1[buf1]; n1[buf1] = buf2;
    }
    rnd(a, n1);
    cout << "you have to put the numbers in ascending order\ncontrol:\n 1.enter the number to be moved\n 2.your number will move to empty space\nyou win, if puzzle looks like this:\n";
    ar(a1);
    cout << "*********************************************\n";
    ar(a);
    cout << "choose a player\n1.you\n2.computer\n";
    cin >> ch;
    switch (ch)
    {
    case 1: ved(a, a1);  break;
    case 2: pkved(a, a1); break;
    default: cout << "error!" << endl;
    }
    
    return 0;
}
void rnd(int** a, int* n1)
{
    for (int i = 0, k = 0; i < m; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (i == m - 1 && j == m - 1)   a[i][j] = 0;
            else a[i][j] = n1[k++];
        }
    }
}
void ar(int** a)
{
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (a[i][j] == 0) cout << "    "; else if (a[i][j] <= 9) cout << ' ' << a[i][j] << "  "; else  cout << ' ' << a[i][j] << ' ';
        }
        cout << endl;
    }
}
void ved(int** a, int** a1)
{
    int boo = 1; int b = 0;
    int num;
    cout << "enter the number\n";
    cin >> num;
    boo = sw(a, a1, num);
    if (boo == 1) { cout << "try again\n"; ved(a, a1); }
    else if (boo == 0) cout << "you won!\n";
    else if (boo == 2) { ar(a); ved(a, a1); }
}
void pkved(int** a, int** a1)
{
    int boo = 1; int b = 0;
    int num;
    num = rand() % n + 1;
    boo = sw(a, a1, num);
    if (boo == 1)  pkved(a, a1); 
    else if (boo == 0) cout << "computer won!\n";
    else if (boo == 2) { cout << num << endl; ar(a); pkved(a, a1); }
}
int sw(int** a, int** a1, int num)
{
    int boo = 1; int b = 0;
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (a[i][j] == 0) { buf1 = i; buf2 = j; }
            if (a[i][j] == num && a[i][j - 1] == 0 || a[i][j] == num && a[i][j + 1] == 0 || a[i][j] == num && a[i + 1][j] == 0 || a[i][j] == num && a[i - 1][j] == 0) { a[i][j] = 0; boo = 0; }
        }
    }
    if (boo==1) { return boo; }
    else if (boo==0) {
        a[buf1][buf2] = num;
        cout << endl;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (a[i][j] == a1[i][j]) { b++; }
            }
        }
        if (b >= n)  return boo;
        else { boo = 2; return boo; }
    }
}


user
I counted 27 "{"s in that text.
assistant