A string contains three parts separated by space. First two parts are strings and the third part is an integer.
The output of the below program is surprising me.
This line is wrong:
arr=malloc(N*sizeof **arr);
it should be:
arr=malloc(N*sizeof *arr);
**arr
is a char
, so it's only allocating space for N
bytes, but you need space for N
pointers, which are 4 bytes. So you're not allocating enough space, and then you're writing outside the array bounds, resulting in undefined behavior.
DEMO