1. 程式人生 > >擷取字串前面字元並替換

擷取字串前面字元並替換

wlanip 192.168.1.22

            char ps[128]={0};  
            char ptr[32]={0}; 
            char *ret;
            int len1,len2;
            printf("wlani=%s\n",wlanip);
            strcpy(ptr,wlanip);
            printf("ptr=%s\n",ptr);
            ret = strrchr(ptr,'.');
            len1=strlen(ptr);
            len2=strlen(ret);
            ptr[len1-len2]='\0';
            printf("ptr=%s\n",ptr);
            strcat(ptr,".1");
            printf("ptr=%s\n",ptr);


輸出:192.168.1.1