c - segmentation fault when writing to a char to a char array -


i writing code processing 2-d char array.

char *board[] = {"aa"}; 

i pass array function

 search(board, row, col);  ..........  bool search(char** boards, int row, int col)  {       // inside function, want modify boards[x][y]        // board within x , y, x < row, y < col       // segmentation fault here because boards        // allocated static memory , cannot changed.       boards[x][y] = 'c';  } 

in c++, can use

 vector< vector<char> boards 

to change elements in specific location. in c, there no vector.

is has advice how modify boards 2-d array? thanks.

the problem making array of pointers, , set pointers ppint string constants. memory of string constants not modifiable, writing causes segmentation fault.

changing array of pointers 2d array of characters fix problem

char board[][10] = {"aa", "bb"}; 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -