c中没有字符串类型,更没有类似于Java这种语言中那么简单的处理字符串的各种方法。但是我们经常会遇到这样的问题,给你一个字符串,去掉其中的空格,或者反转字符串,当然这些在网上也有很多的解法,由于在网上没有看到较好的去掉空格的代码,所以贴下我自己的代码,可能其中问题多多,还望多多指教:)
char * strim(char * str)
{
char * tail = str;
char * next = str;
while(*next)
{
if(*next != ' ')
{
if(tail < next)
*tail = *next;
tail++;
}
next++;
}
*tail = '\0';
return str;
}