标签:
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<assert.h> char *replace_blank(char src[]) { assert(src ); int blank = 0; char *psrc = src ; while (*psrc) //统计空格个数,同时让psrc指向‘\0' { if (*psrc == ' ' ) blank++; psrc++; } while (blank) { if (*psrc== ' ' ) //遇到空格开始替换 { *(psrc+blank*2)= '0'; *(psrc+blank*2-1)= '2'; *(psrc+(--blank)*2)= '%'; } else *(psrc+blank*2)= *psrc; psrc--; } return src ; } int main() { char src[50] = { 0 }; gets(src); char *ret = replace_blank(src); printf( "%s\n", ret); system( "pause"); return 0; }
标签:
原文地址:http://blog.csdn.net/lf_2016/article/details/51379511