Tristen
Tristen

Reputation: 382

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

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)

Upvotes: 0

Views: 45

Answers (1)

suvojit_007
suvojit_007

Reputation: 1728

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';
    }

Upvotes: 2

Related Questions