Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int ctoi(char);

int main()
{
    int H, W;
    cin >> H >> W;

    vector<string> array;

    rep(i, H)
    {
        string S;
        cin >> S;
        array.push_back(S);
    }

    rep(i, H)
    {
        rep(j ,W)
        {
            if (array[i][j] != '#')
            {
                int num = 0;
                if (i!=0)
                {
                    if (array[i-1][j] == '#')
                    {
                        num++;
                    }
                }
                if (i!=0 && j!=0)
                {
                    if (array[i-1][j-1] == '#')
                    {
                        num ++;
                    }
                }
                if (j!=0)
                {
                    if (array[i][j-1] == '#')
                    {
                        num++;
                    }
                }
                if (i!=H-1 && j!=0)
                {
                    if (array[i+1][j-1] == '#')
                    {
                        num ++;
                    }
                }
                if (i != H-1)
                {
                    if (array[i+1][j] == '#')
                    {
                        num ++;
                    }
                }
                if (i != H-1 && j != W-1)
                {
                    if (array[i+1][j+1] == '#')
                    {
                        num ++;
                    }
                }
                if (j != W-1)
                {
                    if (array[i][j+1] == '#')
                    {
                        num++;
                    }
                }
                if (i != 0 && j != W-1)
                {
                    if (array[i-1][j+1] == '#')
                    {
                        num ++;
                    }
                }
                char tmp;
                sprintf(tmp, "%d", num); 
                array[i][j] = tmp;
            }
        }
    }
    

    rep(i, H)
    {
        rep(j, W)
        {
            cout << array[i][j];
        }
        cout << endl;
    }
}


int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c -'0';
    }
    return -1;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:90:25: error: invalid conversion from 'char' to 'char*' [-fpermissive]
   90 |                 sprintf(tmp, "%d", num);
      |                         ^~~
      |                         |
      |                         char
In file included from /usr/include/c++/14/cstdio:42,
                 from /usr/include/c++/14/ext/string_conversions.h:45,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/stdio.h:365:38: note:   initializing argument 1 of 'int sprintf(char*, const char*, ...)'
  365 | extern int sprintf (char *__restrict __s,
      |                     ~~~~~~~~~~~~~~~~~^~~