Having a weird problem while converting char pointer to char array in C/C++ .
For a specific need i need to split a char pointer into two char arrays The char pointer has 4 charecters and 2 char arrays should hold 2 chaecters from the pointer Like this ###################################### char * n = "1023" char a[2]; char b[2]; a[0] = n[0]; a[1] = n[1]; b[0] = n[3]; b[1] = n[4]; Now array 'a' and 'b' should hold and print the value 10 and 23 respectively but except desired output, it sometimes prints unwanted characters or some wrong value https://code.sololearn.com/cBje1CPy7Q2V/?ref=app I tried doing same thing using 'strcpy()' and storing the pointer into a bigger sized array before splitting into two smaller arrays ###################################### https://code.sololearn.com/cHSfNm2681Qh/?ref=app A help to solve this problem will be highly appreciated Thank you. NB: Question Code 1: Code without strcpy() Question Code 2: Code using strcpy()