从在C字符串去掉空格? [英] Removing Spaces from a String in C?

查看:181
本文介绍了从在C字符串去掉空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是取消C字符串中的空格最简单,最有效的方法是什么?

What is the easiest and most efficient way to remove spaces from a string in C?

推荐答案

最简单有效的通常不会一起去...

Easiest and most efficient don't usually go together...

下面是一个可能的解决方案(未经测试):

Here's a possible solution (untested):

void RemoveSpaces(char* source)
{
  char* i = source;
  char* j = source;
  while(*j != 0)
  {
    *i = *j++;
    if(*i != ' ')
      i++;
  }
  *i = 0;
}

这篇关于从在C字符串去掉空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆