C言語では文字列の中から特定の文字だけを除去する関数は
用意されていないので自作する必要がある。
しかしインターネットで公開されている関数は再帰呼び出しの関数など
サンプルとしてはあまり適切ではないのでここで紹介することにした。
【 サンプルC/400 】
0001.00 #include
0002.00 #include
0003.00 #include
0004.00
0005.00 #define TRUE 0
0006.00 #define FALSE -1
0007.00 char* rmvchar(char ch, char* string);
0008.00
0009.00 void main(void){
0010.00 char str[48];
0011.00
0012.00 printf("** TESTRMV2: 文字の除去 **\n");
0013.00 getchar();
0014.00 strcpy(str, "ASIA AMERICA JAPAN");
0015.00 printf("%s から文字 A だけを除去します。 \n", str);
0016.00 getchar();
0017.00 strcpy(str, rmvchar('A', str));
0018.00 printf("==> 結果は %s です。 \n", str);
0019.00 getchar();
0020.00 }
0021.00 /***********************************/
0022.00 char* rmvchar(char ch, char* string)
0023.00 /***********************************/
0024.00 {
0025.00 char* ptr;
0026.00 int pos;
0027.00
0028.00 while((ptr = strchr(string, ch)) != NULL){/*while*/
0029.00 pos = (int)(ptr - string);
0030.00 strcpy(&string[pos], &string[pos+1]);
0031.00 }/*while*/
0032.00 return string;
0033.00 }

【解説】
処理するのは rmvchar ( remove charactor ) という名前の関数であり
文字列 string に文字 ch が含まれていれば複数個あってもすべて
除去して結果を *char として戻す。
もし ch が含まれていない場合は同じ文字列 string を戻す。
