Question About Overwriting .exe Code & File Size Changings - C/C++

Assume i have 4KB .exe file & opened it by any standard function on C++.

1. lets say i want to overwrite "xxx.xxx.xxx.xxx", where x represents IP address. These x's are 15 bytes max. Anyhow, it could be less. So when user inserts lets say "12.44.120.31", its only 12 bytes, so 12 bytes will overwrite 15 bytes, what about the 3 bytes left? If its left there, the 3 bytes will corrupt the new inserted IP, thats what forces me to move all data to temp file. Otherwise, i would just overwrite on the fly. I will use circular buffer to read the file


2. I don't have knowledge about Big O's & Analysis of Algorithms mathematically. Its very interesting, i will have to take courses for it. Anyway, as a professional developer do you really use it in a real life?
1. It's not a problem when the string you're trying to write is smaller than the one that already exists. You just add padding zeroes at the end.
The problem is when the string you're trying to write is bigger.
lets say i have "255.255.255.255" as default. User inserted "22.44.200.95"

User IP will overwrite the default IP, so it will look like "22.44.200.95255" 255 is remained there i can't append to zero since IP size is not fixed so i won't know when to append zeros anyway. Can you clarify please
('_' will represent '\0' to keep everything aligned.)
Original string: "???.???.???.???_"
New string: "22.44.200.95____"
so i have to mention it as 16 bytes not 15 bytes because '\0' is counted. Right?
Anyhow, i used Hex Workshop to see the default IP address 255.255.255.255 & i found it there but there wasn't any terminating character '\0'...Any idea?
Then either it's not a C string, or that's not what you're looking for.
If it's not a C string, then just put leading zeroes for each base 256 digit: 001.010.100.255
yes the IP is of type const *char. If const *char puts \0 at the end just like string does. Does it?

putting zeros on the front is a good idea 001.010.100.255
Topic archived. No new replies allowed.