#include <stdio.h>
#include <stdlib.h>
/*去除左边空格*/
void trimLeftSpace(char *p)
{
if(*p != ' ')
return;
char *str = p;
while(*str == ' ')
str++;
while(*p++ = *str++);
}
/*去除右边空格*/
void trimRightSpace(char *p)
{
while(*p)
p++;
while(*--p == ' ')
*p = '\0';
}
/*去除所有空格*/
void trimAllSpace(char *p)
{
char *str = p;
while(*p)
{
if(*p != ' ')
*str++ = *p;
p++;
}
*str = '\0';
}
void trimAllSpace(char *p)
{
char *str = p;
while(*p)
{
if(*p != ' ')
*str++ = *p;
p++;
}
*str = '\0';
}
int main(int argc, char *argv[])
{
char buf[100] = " chi na ";
char saveBuf[100];
// trimLeftSpace(buf);
// trimRightSpace(buf);
trimAllSpace(buf);
printf("***%s***\n",buf);
return 0;
}
字符串去除空格,解决文件登陆问题
最新推荐文章于 2023-05-29 14:39:17 发布