Variable assignment to Arrays inside of function without globals or changing function inputs in C

0

I have a specific set of constraints. The problem wouldn't be difficult if it wasn't for the constraints.

    #define ROW 12
    #define COL 6   

    int main (void)
    {
    // Code can be changed in brackets
        char arr[ROW][COL];
        function1(arr);
        printf("%s", arr[0][0]); 
    }


    void function1(char arr[][COL]){  //Can't change anything in this line
    // Code allowed to be changed inside brackets
    // Trying to assign values to multi-dim array as shown below
        arr[0][0] = 'O';
    }

Process finished with exit code -1073741819 (0xC0000005)

c
asked on Stack Overflow Oct 25, 2018 by Tristen • edited Oct 25, 2018 by Mikhail Kholodkov

1 Answer

2

change arr[0][0] = "O"; to arr[0][0] = 'O';

Specify the proper format in printf("%s", arr[0][0]); //<-----should be %c

#define ROW 12
#define COL 6   

    int main (void)
    {
    // Code can be changed in brackets
        char arr[ROW][COL];
        function1(arr);
        printf("%c", arr[0][0]); //<----------- should be %c
    }


    void function1(char arr[][COL]){  //Can't change anything in this line
    // Code allowed to be changed inside brackets
    // Trying to assign values to multi-dim array as shown below
        arr[0][0] = 'O';
    }
answered on Stack Overflow Oct 25, 2018 by suvojit_007 • edited Oct 25, 2018 by suvojit_007

User contributions licensed under CC BY-SA 3.0