C 删除字符串中某个指定的字符
#include <stdio.h> char *del_char(char *str, char ch) { unsigned char i=0,j=0; while(str[i] != '\0') { if(str[i] != ch) //只有在不是空格的情况下目标才会移动赋值 { str[j++] = str[i]; } i++; //源一直移动 } str[j] = '\0'; return str; } int main(int argc, const char *argv[]) { char ch; int i=0; char a[1024] = {'\0'}; while((ch=getchar()) != '\n') { a[i++] = ch; } char *s = del_char(a,' '); puts(s); return 0; }