If you have char arr[10] = "1234567890"
as per your question, note that it is not a string since it has no room for the NUL terminator (would need size 11
, or left empty []
for the compiler to count for you). Assuming you want two strings out of it, you need to copy the two halves to separate arrays, e.g.:
char topHalf[6], bottomHalf[6]; // 6 = 5 + NUL
(void) memcpy(topHalf, arr, 5); // copy 5 chars from beginning of arr
(void) memcpy(bottomHalf, arr + 5, 5); // arr + 5 to skip the 5 in topHalf
topHalf[5] = '\0'; // terminate string
bottomHalf[5] = '\0'; // "
9
solved how to break 10 digit number into two 5 digit number in c?