#include <stdio.h> int replace(char *p) { #if 0 while(*p!='\0') { if(*p==' ') { printf("%%20"); } else { printf("%c",*p); } p++; } #endif//結束#if 0 if (*p == ' ') { return 1; } else return 2; printf("\n"); } int main() { char arr[] ="we are happy."; char *p = arr; int ret = 0; while (*p != '\0') { ret = replace(p); if (ret == 1) { printf("%%20"); } if (ret == 2) { printf("%c",*p); } p++; } printf("\n"); return 0; }
運行結果: