Your pos_o variable (which is a pointer to a pointer variable) stores the base-address of contiguous segment of memory for 1 unit - and here the unit is actually base address of another memory location. (And for this another memory location you are nowhere allocating memory) I think you understand this because you have already written this line int **pos_o = malloc(sizeof(int *)); - (here you are allocating 1 unit by sizeof(int*) for a pointer variable). But nowhere you have allocated memory for variable to which this pointer variable will point to.
Not allocating the memory is not a problem, but referencing the memory location without allocating the memory might result in segmentation fault.
You should have something like pos_o[0]=malloc(sizeof(int)) (I suggest allocating it for only one integer variable as I see your variable k is always 0, and you are accessing only one element). Consider allocating more (appropriate amount of) memory if you have your variable k being modified by some logic that you have not mentioned here.
Read more about segmentation faults from here.
pos_o = malloc(…);throws away all the hard work done before that, leaking memory and leaving you with incomplete data structures with uninitialized pointers which lead to your crash. It's odd to have the variablekset to 0 simply so that you can eventually writepos_o[0][0] = count;(because what you've shown is equivalent to that). You don't return a value from the function, either — that's bad. Presumably, you're missingreturn pos_o;. And you're only allocating oneint *...not an array on them. What are you trying to do?for (i = 0; map[i][j] != '\0'; i++)jneeds to be reset after each inner loop. Or perhaps you needmap[i][0] != '\0';pos_o[0] = malloc(...). Otherwisepos_o[0]is an uninitialized pointer.