Within my program, I need a string array to be 8 characters in length. The string, when input, is not necessarily 8 characters, and therefore i need to add '0' to the front of the string to increase its length to 8, and move the existing content up so that it is on the end of the string.
For example, if an input was 111, it is necessary that I manipulate the string to 00000111.
The method must be dynamic, to deal with inputs larger and smaller than 3.
I am new to C++, so thanks in advance.
char arr[8] = "111"; // C string you want to modify
int len = 8-strlen(arr); // get the missing part size
memmove(arr+len,arr,strlen(arr)); // move the string characters to the end
for ( int i = 0; i < len; i++ ) // fill the beginning characters with '0'
arr[i] = '0';