---
# System prepended metadata

title: '[1108. Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/)'

---

# [1108. Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/)
![](https://i.imgur.com/ALAuUNh.png)
![](https://i.imgur.com/cvHBDDB.png)
char * defangIPaddr(char * address){
    int addressLen = strlen(address);
    int defAddressLen = addressLen + 7;
    char * defAddress = (char *)malloc(defAddressLen);
    memset(defAddress, 0, defAddressLen);

    int offset = 0;
    for(int i=0; i<addressLen; i++){
        if(address[i] == '.'){
            defAddress[offset] = '[';
            defAddress[offset+1] = '.';
            defAddress[offset+2] = ']';
            offset += 3;
        }else{
            defAddress[offset] = address[i];
            offset++;
        }
    }

    return defAddress;
}