thx.....
I changed it to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
//Assume size is determined already...
typedef unsigned char BYTE; // if not defined
BYTE IPAddrOld[] = { 1, 2, 3, 4, 5}; // Declaring new char array with already initialized values, size=5*sizeof(BYTE) = 5 bytes
BYTE IPAddrNew[} = { 88, 55, 33, 1, 00}; // Same as earlier, size=5*sizeof(BYTE) = 5 bytes
/ / I assume that size is 5, and memblock = new char[5]
for (size_t sz = 0; sz < size; ++sz) {
if (memcmp(&memblock[sz], IpAddrOld, sizeof(IPAddrOld) == 0) {
memcpy(&memblock[sz], IPAddrNew, sizeof(IPAddrNew);
break; // done.
}
}
| |
Last Question:
BYTE IPAddrOld[] = { 1, 2, 3, 4, 5, 6, 44, 66, 33, 55, 66, ff}; // Declaring new char array with already initialized values, size=5*sizeof(BYTE) = 5 bytes
BYTE IPAddrNew[} = { 88, 55, 33, 1, 00}; // Same as earlier, size=5*sizeof(BYTE) = 5 bytes
What if i want to replace 6 up to 55 with 88 up to 00? Size of IPAddrOld[] is larger...What i though to do is the following:
1. before i go into if(memcmp()), i put every five chars into a variable string.
2. compare it with the string 6,44,66,33,55 - if true, then proceed to if(memcmp()). If not true, repeat the loop.
Do you have any suggestions?
I hope to find a reply...