Hope im in the correct room.
Hi All
Ive been wrecking my brain all day to try and check this array and where there exists only one char =>add second char 0 to it. whilst leaving the others alone.
char usable_MAC[19] = "FF:35:0:E1:80:FF";
Ive shown below my last attempt but no success.
result => i want to see is where there is "0" should now see "00" whilst leaving the rest along.
Note-> this single char could be anywhere in this array
BELOW IS WHAT I WANT as RESULT
char usable_MAC[19] = "FF:35:00:E1:80:FF";
int desiredSize = 17;
// Padding character
char paddingChar = '0';
// Create a new array with padding
char padded_MAC[desiredSize];
// Initialize the padded array with null characters
memset(padded_MAC, '\0', desiredSize);
// Copy characters from the original MAC address to the padded array
int i, j;
for (i = 0, j = 0; i < strlen(usable_MAC) && j < desiredSize - 1; ++i, ++j) {
padded_MAC[j] = usable_MAC[i];
// Check for a single character and pad with '0'
if (usable_MAC[i] == ':' && usable_MAC[i + 2] == ':' && usable_MAC[i + 1] != '0') {
padded_MAC[++j] = paddingChar;
}
}
// Null-terminate the padded array
padded_MAC[desiredSize - 1] = '\0';
// Display the padded MAC address
printf("Padded MAC: %s\n", padded_MAC);
Thanks in advance