C++ 将“we are happy”中的空格替换成%20,即“we%20are%20happy”

来源:互联网 发布:java编写游戏 编辑:程序博客网 时间:2024/06/03 15:16
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){    char c[100] = "we are happy";    int space_num = 2;    int pos = strlen(c);    int new_pos = pos + (2 * space_num);    while(pos >= 0)    {        if(c[pos] == ' ')        {            c[new_pos--] = '0';            c[new_pos--] = '2';            c[new_pos--] = '%';            pos--;        }        else        {            c[new_pos--] = c[pos--];        }    }    printf("%s\n", c);    return 0;}
0 0
原创粉丝点击