函数说明
- 将字符串中的所有空格都去掉。
- 该函数简单但实用性强,可以作为字符串过滤器使用,随便改一下就可以实现去掉任意字符的功能,建议程序员的代码库里可以收藏一段该类型代码,用取方便。
函数实现
#include <stdio.h>/*** 去除空格* @param source* @param storage*/
void HandleChara(char * source,char *storage)
{int i=0;int length = strlen(source);while(i<length){if((*source != ' ')&&(*source != '\t')&&(*source != '\n')){*storage=*source;storage++;}source++;i++;}
}int main() {char source[50]="",storage[50]="";printf("请输入一段字符串:");gets(source);HandleChara(source,storage);printf("处理后的字符串:%s",storage);return 0;
}
运行实现